From 72f70f6128b8758d788d7db64ce1a327de41cc4b Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Sun, 21 Jun 2020 18:59:56 -0700 Subject: [PATCH 01/31] Added proxy command tab expansion with tests. --- src/GitTabExpansion.ps1 | 34 ++++ test/GitProxyCommandExpansion.Tests.ps1 | 235 ++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 test/GitProxyCommandExpansion.Tests.ps1 diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 6e0606738..b695a2dea 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -472,6 +472,38 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { } } +function Expand-GitProxyCommand($Command) { + if ($Command -notmatch '^(?\S+)\s+(?.*)$') { + return $Command; + } + + # Store arguments for replacement later + $Arguments = $Matches['args'] + + # Traverse alias chain to command name + $CommandName = $Matches['command'] + while(Test-Path Alias:\$CommandName) { + $CommandName = Get-Alias -Name $CommandName | Select-Object -ExpandProperty 'ResolvedCommandName' + } + + if(Test-Path Function:\$CommandName) { + $Definition = Get-Command -Name $CommandName -CommandType 'Function' | Select-Object -ExpandProperty 'Definition' + + # The regular expression here matches commands + $args. Some restrictions on delimiting whitespace + # have been made to disallow newlines in the middle of the command without the backtick (`) character preceding them + $DefinitionRegex = "(^|[|;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|``\r?\n)+\S+)*)(([ \t]|``\r?\n)+\`$args)\s*($|[|;`n])" + + if ($Definition -match $DefinitionRegex) { + $Cmd = $Matches['cmd'] + # Clean up the parameters by removing delimiting whitespace and backtick preceding newlines + $Params = $Matches['params'] -replace '`$|`\r?\n', '' -replace '\s+', ' ' + return $Cmd.Trim() + ' ' + $Params.Trim() + ' ' + $Arguments.Trim() + } + } + + return $Command +} + function WriteTabExpLog([string] $Message) { if (!$global:GitTabSettings.EnableLogging) { return } @@ -491,6 +523,7 @@ if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { # The Expand-GitCommand expects this trailing space, so pad with a space if necessary. $padLength = $cursorPosition - $commandAst.Extent.StartOffset $textToComplete = $commandAst.ToString().PadRight($padLength, ' ').Substring(0, $padLength) + $textToComplete = Expand-GitProxyCommand($textToComplete) WriteTabExpLog "Expand: command: '$($commandAst.Extent.Text)', padded: '$textToComplete', padlen: $padLength" Expand-GitCommand $textToComplete @@ -514,6 +547,7 @@ else { function TabExpansion($line, $lastWord) { $lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart() + $lastBlock = Expand-GitProxyCommand($lastBlock) $msg = "Legacy expand: '$lastBlock'" switch -regex ($lastBlock) { diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 new file mode 100644 index 000000000..a8cce2d2b --- /dev/null +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -0,0 +1,235 @@ +BeforeAll { + . $PSScriptRoot\Shared.ps1 +} + +Describe 'CommandExpansion Tests' { + Context 'Proxy Subcommand TabExpansion Tests' { + BeforeEach { + if(Test-Path Function:\Invoke-GitFunction) { + Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup + } + if(Test-Path Alias:\igf) { + Rename-Item -Path Alias:\igf -NewName igfbackup + } + } + AfterEach { + if(Test-Path Function:\Invoke-GitFunction) { + Remove-Item Function:\Invoke-GitFunction + } + if(Test-Path Function:\Invoke-GitFunctionBackup) { + Rename-Item Function:\Invoke-GitFunctionBackup Invoke-GitFunction + } + if(Test-Path Alias:\igf) { + Remove-Item Alias:\igf + } + if(Test-Path Alias:\igfbackup) { + Rename-Item Alias:\igfbackup igf + } + } + It 'Expands a single line command' { + function global:Invoke-GitFunction { + git checkout $args + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout ' + } + It 'Expands a single line command with parameter' { + function global:Invoke-GitFunction { + git checkout -b $args + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout -b ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout -b ' + } + It 'Expands the first line in command' { + function global:Invoke-GitFunction { + git checkout $args + $a = 5 + Write-Host $null + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout ' + } + It 'Expands the middle line in command' { + function global:Invoke-GitFunction { + $a = 5 + git checkout $args + Write-Host $null + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout ' + } + It 'Expands the last line in command' { + function global:Invoke-GitFunction { + $a = 5 + Write-Host $null + git checkout $args + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout ' + } + It 'Expands semicolon delimited commands' { + function global:Invoke-GitFunction { + $a = 5; git checkout $args; Write-Host $null; + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout ' + } + It 'Expands mixed semicolon delimited and newline commands' { + function global:Invoke-GitFunction { + $a = 5; Write-Host $null + git checkout $args; Write-Host $null; + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout ' + } + It 'Expands mixed semicolon delimited and newline multiline commands' { + function global:Invoke-GitFunction { + $a = 5; Write-Host $null + git ` + checkout ` + $args; Write-Host $null; + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout ' + } + It 'Expands multiline command' { + function global:Invoke-GitFunction { + git ` + checkout ` + $args + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout ' + } + It 'Expands multiline command with parameter' { + function global:Invoke-GitFunction { + git ` + checkout ` + -b ` + $args + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout -b ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout -b ' + } + It 'Does not expand command if $args is not present' { + function global:Invoke-GitFunction { + git checkout + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'igf ' + } + It 'Does not expand command if $args is not attached to the git command' { + function global:Invoke-GitFunction { + $a = 5 + git checkout + Write-Host $args + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'igf ' + } + It 'Does not expand multiline command if $args is not attached to the git command' { + function global:Invoke-GitFunction { + $a = 5 + git ` + checkout + Write-Host $args + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'igf ' + } + } + Context 'Proxy Subcommand TabExpansion Tests' { + BeforeEach { + if(Test-Path Function:\Invoke-GitFunction) { + Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup + } + } + AfterEach { + if(Test-Path Function:\Invoke-GitFunction) { + Remove-Item Function:\Invoke-GitFunction + } + if(Test-Path Function:\Invoke-GitFunctionBackup) { + Rename-Item -Path Function:\Invoke-GitFunctionBackup -NewName Invoke-GitFunction + } + } + It 'Tab completes without subcommands' { + function global:Invoke-GitFunction { git whatever $args } + $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module GitTabExpansionInternal $CommandText + + $result | Should -Be @() + } + It 'Tab completes bisect subcommands' { + function global:Invoke-GitFunction { git bisect $args } + $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module GitTabExpansionInternal $CommandText + + $result -contains '' | Should -Be $false + $result -contains 'start' | Should -Be $true + $result -contains 'run' | Should -Be $true + + $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction s' + $result2 = & $module GitTabExpansionInternal $CommandText + + $result2 -contains 'start' | Should -Be $true + $result2 -contains 'skip' | Should -Be $true + } + It 'Tab completes remote subcommands' { + function global:Invoke-GitFunction { git remote $args } + $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module GitTabExpansionInternal $CommandText + + $result -contains '' | Should -Be $false + $result -contains 'add' | Should -Be $true + $result -contains 'set-branches' | Should -Be $true + $result -contains 'get-url' | Should -Be $true + $result -contains 'update' | Should -Be $true + + $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction s' + $result2 = & $module GitTabExpansionInternal $CommandText + + $result2 -contains 'set-branches' | Should -Be $true + $result2 -contains 'set-head' | Should -Be $true + $result2 -contains 'set-url' | Should -Be $true + } + } +} From f8d94fbfbbf96d2d8826e3ef2f5c6102fc5eb804 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Sun, 21 Jun 2020 19:57:52 -0700 Subject: [PATCH 02/31] Separated regular expression into a separate function for reuse. Added proxy command names to the argument completer. --- src/GitTabExpansion.ps1 | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index b695a2dea..ad8ada8bf 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -472,6 +472,12 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { } } +function script:Get-GitProxyCommandRegex() { + # The regular expression here matches commands + $args. Some restrictions on delimiting whitespace + # have been made to disallow newlines in the middle of the command without the backtick (`) character preceding them + return "(^|[|;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|``\r?\n)+\S+)*)(([ \t]|``\r?\n)+\`$args)\s*($|[|;`n])" +} + function Expand-GitProxyCommand($Command) { if ($Command -notmatch '^(?\S+)\s+(?.*)$') { return $Command; @@ -483,16 +489,12 @@ function Expand-GitProxyCommand($Command) { # Traverse alias chain to command name $CommandName = $Matches['command'] while(Test-Path Alias:\$CommandName) { - $CommandName = Get-Alias -Name $CommandName | Select-Object -ExpandProperty 'ResolvedCommandName' + $CommandName = Get-Item -Path Alias:\$CommandName | Select-Object -ExpandProperty 'ResolvedCommandName' } if(Test-Path Function:\$CommandName) { - $Definition = Get-Command -Name $CommandName -CommandType 'Function' | Select-Object -ExpandProperty 'Definition' - - # The regular expression here matches commands + $args. Some restrictions on delimiting whitespace - # have been made to disallow newlines in the middle of the command without the backtick (`) character preceding them - $DefinitionRegex = "(^|[|;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|``\r?\n)+\S+)*)(([ \t]|``\r?\n)+\`$args)\s*($|[|;`n])" - + $Definition = Get-Item -Path Function:\$CommandName | Select-Object -ExpandProperty 'Definition' + $DefinitionRegex = Get-GitProxyCommandRegex if ($Definition -match $DefinitionRegex) { $Cmd = $Matches['cmd'] # Clean up the parameters by removing delimiting whitespace and backtick preceding newlines @@ -512,7 +514,8 @@ function WriteTabExpLog([string] $Message) { } if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { - $cmdNames = "git","tgit","gitk" + $proxyCmdNames = Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match (Get-GitProxyCommandRegex) } + $cmdNames = "git","tgit","gitk" + $proxyCmdNames $cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name Microsoft.PowerShell.Core\Register-ArgumentCompleter -CommandName $cmdNames -Native -ScriptBlock { From c520b5dbfdafbe542ae4a8bea10da96cbbb6d4eb Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Sun, 21 Jun 2020 20:03:17 -0700 Subject: [PATCH 03/31] Added explicit parameter names. --- src/GitTabExpansion.ps1 | 4 ++-- test/GitProxyCommandExpansion.Tests.ps1 | 26 ++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index ad8ada8bf..93ab86a3c 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -488,11 +488,11 @@ function Expand-GitProxyCommand($Command) { # Traverse alias chain to command name $CommandName = $Matches['command'] - while(Test-Path Alias:\$CommandName) { + while(Test-Path -Path Alias:\$CommandName) { $CommandName = Get-Item -Path Alias:\$CommandName | Select-Object -ExpandProperty 'ResolvedCommandName' } - if(Test-Path Function:\$CommandName) { + if(Test-Path -Path Function:\$CommandName) { $Definition = Get-Item -Path Function:\$CommandName | Select-Object -ExpandProperty 'Definition' $DefinitionRegex = Get-GitProxyCommandRegex if ($Definition -match $DefinitionRegex) { diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index a8cce2d2b..15df1c39a 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -5,25 +5,25 @@ BeforeAll { Describe 'CommandExpansion Tests' { Context 'Proxy Subcommand TabExpansion Tests' { BeforeEach { - if(Test-Path Function:\Invoke-GitFunction) { + if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup } - if(Test-Path Alias:\igf) { + if(Test-Path -Path Alias:\igf) { Rename-Item -Path Alias:\igf -NewName igfbackup } } AfterEach { - if(Test-Path Function:\Invoke-GitFunction) { - Remove-Item Function:\Invoke-GitFunction + if(Test-Path -Path Function:\Invoke-GitFunction) { + Remove-Item -Path Function:\Invoke-GitFunction } - if(Test-Path Function:\Invoke-GitFunctionBackup) { + if(Test-Path -Path Function:\Invoke-GitFunctionBackup) { Rename-Item Function:\Invoke-GitFunctionBackup Invoke-GitFunction } - if(Test-Path Alias:\igf) { - Remove-Item Alias:\igf + if(Test-Path -Path Alias:\igf) { + Remove-Item -Path Alias:\igf } - if(Test-Path Alias:\igfbackup) { - Rename-Item Alias:\igfbackup igf + if(Test-Path -Path Alias:\igfbackup) { + Rename-Item -Path Alias:\igfbackup -NewName igf } } It 'Expands a single line command' { @@ -179,15 +179,15 @@ Describe 'CommandExpansion Tests' { } Context 'Proxy Subcommand TabExpansion Tests' { BeforeEach { - if(Test-Path Function:\Invoke-GitFunction) { + if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup } } AfterEach { - if(Test-Path Function:\Invoke-GitFunction) { - Remove-Item Function:\Invoke-GitFunction + if(Test-Path -Path Function:\Invoke-GitFunction) { + Remove-Item -Path Function:\Invoke-GitFunction } - if(Test-Path Function:\Invoke-GitFunctionBackup) { + if(Test-Path -Path Function:\Invoke-GitFunctionBackup) { Rename-Item -Path Function:\Invoke-GitFunctionBackup -NewName Invoke-GitFunction } } From debc66a15622db4757f658eeeeab575f50e8e772 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Sun, 21 Jun 2020 20:06:36 -0700 Subject: [PATCH 04/31] Simplified cleanup in the Expand-GitProxyCommand function. --- src/GitTabExpansion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 93ab86a3c..660e81512 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -498,7 +498,7 @@ function Expand-GitProxyCommand($Command) { if ($Definition -match $DefinitionRegex) { $Cmd = $Matches['cmd'] # Clean up the parameters by removing delimiting whitespace and backtick preceding newlines - $Params = $Matches['params'] -replace '`$|`\r?\n', '' -replace '\s+', ' ' + $Params = $Matches['params'] -replace '`\r?\n', '' -replace '\s+', ' ' return $Cmd.Trim() + ' ' + $Params.Trim() + ' ' + $Arguments.Trim() } } From 2becd9c4d5909e2a74876c3d26ef7aff058ccf9c Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Sun, 21 Jun 2020 20:10:02 -0700 Subject: [PATCH 05/31] Removed an errant tab in the git proxy command test file. --- test/GitProxyCommandExpansion.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index 15df1c39a..8e92a6205 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -132,7 +132,7 @@ Describe 'CommandExpansion Tests' { function global:Invoke-GitFunction { git ` checkout ` - -b ` + -b ` $args } New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' From 819c6b65ee784508f4c2978314b224c381ef1000 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 00:53:59 -0700 Subject: [PATCH 06/31] Added a property to the $GitTabSettings object to configure enabling or disabling of proxy command expansion. --- src/GitTabExpansion.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 660e81512..b87682adb 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -7,6 +7,7 @@ $Global:GitTabSettings = New-Object PSObject -Property @{ '!f() { exec vsts code pr "$@"; }; f' = 'vsts.pr' } EnableLogging = $false + EnableProxyCommandExpansion = $false LogPath = Join-Path ([System.IO.Path]::GetTempPath()) posh-git_tabexp.log } @@ -526,7 +527,9 @@ if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { # The Expand-GitCommand expects this trailing space, so pad with a space if necessary. $padLength = $cursorPosition - $commandAst.Extent.StartOffset $textToComplete = $commandAst.ToString().PadRight($padLength, ' ').Substring(0, $padLength) - $textToComplete = Expand-GitProxyCommand($textToComplete) + if ($global:GitTabSettings.EnableProxyCommandExpansion) { + $textToComplete = Expand-GitProxyCommand($textToComplete) + } WriteTabExpLog "Expand: command: '$($commandAst.Extent.Text)', padded: '$textToComplete', padlen: $padLength" Expand-GitCommand $textToComplete @@ -550,7 +553,9 @@ else { function TabExpansion($line, $lastWord) { $lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart() - $lastBlock = Expand-GitProxyCommand($lastBlock) + if ($global:GitTabSettings.EnableProxyCommandExpansion) { + $lastBlock = Expand-GitProxyCommand($lastBlock) + } $msg = "Legacy expand: '$lastBlock'" switch -regex ($lastBlock) { From 3e49e09f9a1a8c0d23bd03640f739b15ef7e78f4 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 01:19:16 -0700 Subject: [PATCH 07/31] Removed an unnecessary intermediate variable. --- src/GitTabExpansion.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index b87682adb..0666b5640 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -497,10 +497,9 @@ function Expand-GitProxyCommand($Command) { $Definition = Get-Item -Path Function:\$CommandName | Select-Object -ExpandProperty 'Definition' $DefinitionRegex = Get-GitProxyCommandRegex if ($Definition -match $DefinitionRegex) { - $Cmd = $Matches['cmd'] # Clean up the parameters by removing delimiting whitespace and backtick preceding newlines $Params = $Matches['params'] -replace '`\r?\n', '' -replace '\s+', ' ' - return $Cmd.Trim() + ' ' + $Params.Trim() + ' ' + $Arguments.Trim() + return $Matches['cmd'].Trim() + ' ' + $Params.Trim() + ' ' + $Arguments.Trim() } } From 30c1e23fadd1fc3e75aeef2953ee0c77dad8bd6d Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 01:19:32 -0700 Subject: [PATCH 08/31] Added more tests to cover argument replacement. --- test/GitProxyCommandExpansion.Tests.ps1 | 100 +++++++++++++++++++++++- 1 file changed, 96 insertions(+), 4 deletions(-) diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index 8e92a6205..df2f31e99 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -2,8 +2,8 @@ BeforeAll { . $PSScriptRoot\Shared.ps1 } -Describe 'CommandExpansion Tests' { - Context 'Proxy Subcommand TabExpansion Tests' { +Describe 'Proxy Command Expansion Tests' { + Context 'Proxy Command TabExpansion Tests' { BeforeEach { if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup @@ -36,7 +36,7 @@ Describe 'CommandExpansion Tests' { $result = & $module Expand-GitProxyCommand 'igf ' $result | Should -Be 'git checkout ' } - It 'Expands a single line command with parameter' { + It 'Expands a single line command with short parameter' { function global:Invoke-GitFunction { git checkout -b $args } @@ -46,6 +46,16 @@ Describe 'CommandExpansion Tests' { $result = & $module Expand-GitProxyCommand 'igf ' $result | Should -Be 'git checkout -b ' } + It 'Expands a single line command with long parameter' { + function global:Invoke-GitFunction { + git checkout --detach $args + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout --detach ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout --detach ' + } It 'Expands the first line in command' { function global:Invoke-GitFunction { git checkout $args @@ -116,6 +126,19 @@ Describe 'CommandExpansion Tests' { $result = & $module Expand-GitProxyCommand 'igf ' $result | Should -Be 'git checkout ' } + It 'Expands simultaneously semicolon delimited and newline commands' { + function global:Invoke-GitFunction { + $a = 5; + Write-Host $null; + git checkout $args; + Write-Host $null; + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout ' + } It 'Expands multiline command' { function global:Invoke-GitFunction { git ` @@ -128,7 +151,7 @@ Describe 'CommandExpansion Tests' { $result = & $module Expand-GitProxyCommand 'igf ' $result | Should -Be 'git checkout ' } - It 'Expands multiline command with parameter' { + It 'Expands multiline command with short parameter' { function global:Invoke-GitFunction { git ` checkout ` @@ -141,6 +164,19 @@ Describe 'CommandExpansion Tests' { $result = & $module Expand-GitProxyCommand 'igf ' $result | Should -Be 'git checkout -b ' } + It 'Expands multiline command with long parameter' { + function global:Invoke-GitFunction { + git ` + checkout ` + --detach ` + $args + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout --detach ' + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'git checkout --detach ' + } It 'Does not expand command if $args is not present' { function global:Invoke-GitFunction { git checkout @@ -177,6 +213,62 @@ Describe 'CommandExpansion Tests' { $result | Should -Be 'igf ' } } + Context 'Proxy Command Parameter Replacement Tests' { + BeforeEach { + if(Test-Path -Path Function:\Invoke-GitFunction) { + Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup + } + if(Test-Path -Path Alias:\igf) { + Rename-Item -Path Alias:\igf -NewName igfbackup + } + } + AfterEach { + if(Test-Path -Path Function:\Invoke-GitFunction) { + Remove-Item -Path Function:\Invoke-GitFunction + } + if(Test-Path -Path Function:\Invoke-GitFunctionBackup) { + Rename-Item Function:\Invoke-GitFunctionBackup Invoke-GitFunction + } + if(Test-Path -Path Alias:\igf) { + Remove-Item -Path Alias:\igf + } + if(Test-Path -Path Alias:\igfbackup) { + Rename-Item -Path Alias:\igfbackup -NewName igf + } + } + It 'Replaces parameter in $args' { + function global:Invoke-GitFunction { git checkout $args } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction master' + $result | Should -Be 'git checkout master' + $result = & $module Expand-GitProxyCommand 'igf master' + $result | Should -Be 'git checkout master' + } + It 'Replaces short parameter in $args' { + function global:Invoke-GitFunction { git checkout $args } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction -b master' + $result | Should -Be 'git checkout -b master' + $result = & $module Expand-GitProxyCommand 'igf -b master' + $result | Should -Be 'git checkout -b master' + } + It 'Replaces long parameter in $args' { + function global:Invoke-GitFunction { git checkout $args } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction --detach master' + $result | Should -Be 'git checkout --detach master' + $result = & $module Expand-GitProxyCommand 'igf --detach master' + $result | Should -Be 'git checkout --detach master' + } + It 'Replaces mixed parameters in $args' { + function global:Invoke-GitFunction { git checkout $args } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction -q -f -m --detach master' + $result | Should -Be 'git checkout -q -f -m --detach master' + $result = & $module Expand-GitProxyCommand 'igf -q -f -m --detach master' + $result | Should -Be 'git checkout -q -f -m --detach master' + } + } Context 'Proxy Subcommand TabExpansion Tests' { BeforeEach { if(Test-Path -Path Function:\Invoke-GitFunction) { From e387b2d0bdf9d0a98ec492250b13c61f2e41de67 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 01:33:59 -0700 Subject: [PATCH 09/31] Fixed a bug where proxy command expansion would be registered on proxy commands when the expansion was disabled. --- src/GitTabExpansion.ps1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 0666b5640..af1103c06 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -514,8 +514,13 @@ function WriteTabExpLog([string] $Message) { } if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { - $proxyCmdNames = Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match (Get-GitProxyCommandRegex) } - $cmdNames = "git","tgit","gitk" + $proxyCmdNames + $cmdNames = if ($global:GitTabSettings.EnableProxyCommandExpansion) { + # Register proxy commands if the expansion is enabled + "git", "tgit", "gitk" + (Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match (Get-GitProxyCommandRegex) }) + } + else { + "git", "tgit", "gitk" + } $cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name Microsoft.PowerShell.Core\Register-ArgumentCompleter -CommandName $cmdNames -Native -ScriptBlock { From 2ce8e5d35fb7eaa2ed5b41a30fdea612c74c6223 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 01:38:30 -0700 Subject: [PATCH 10/31] Simplified assignment of proxy command names. --- src/GitTabExpansion.ps1 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index af1103c06..77b0b64e9 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -514,12 +514,10 @@ function WriteTabExpLog([string] $Message) { } if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { - $cmdNames = if ($global:GitTabSettings.EnableProxyCommandExpansion) { + $cmdNames = "git","tgit","gitk" + if ($global:GitTabSettings.EnableProxyCommandExpansion) { # Register proxy commands if the expansion is enabled - "git", "tgit", "gitk" + (Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match (Get-GitProxyCommandRegex) }) - } - else { - "git", "tgit", "gitk" + $cmdNames += Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match (Get-GitProxyCommandRegex) } | Select-Object -ExpandProperty 'Name' } $cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name From 0f13ad167027d16e05ed18ccc031bb8efc08c8f1 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 20:22:01 -0700 Subject: [PATCH 11/31] Simplified the args regex group in the command match. --- src/GitTabExpansion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 77b0b64e9..fce9e851d 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -480,7 +480,7 @@ function script:Get-GitProxyCommandRegex() { } function Expand-GitProxyCommand($Command) { - if ($Command -notmatch '^(?\S+)\s+(?.*)$') { + if ($Command -notmatch '^(?\S+)(?.*)$') { return $Command; } From 9ccb7cce52409007cabaa388f66d75ee9a367ebc Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 20:22:52 -0700 Subject: [PATCH 12/31] Switched function declarations in the GitProxyCommandExpansion.Test.ps1 file to script scope. Separated the alias tests into their own context. --- test/GitProxyCommandExpansion.Tests.ps1 | 271 +++++++++++++++--------- 1 file changed, 170 insertions(+), 101 deletions(-) diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index df2f31e99..c4462f26f 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -8,9 +8,6 @@ Describe 'Proxy Command Expansion Tests' { if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup } - if(Test-Path -Path Alias:\igf) { - Rename-Item -Path Alias:\igf -NewName igfbackup - } } AfterEach { if(Test-Path -Path Function:\Invoke-GitFunction) { @@ -19,198 +16,144 @@ Describe 'Proxy Command Expansion Tests' { if(Test-Path -Path Function:\Invoke-GitFunctionBackup) { Rename-Item Function:\Invoke-GitFunctionBackup Invoke-GitFunction } - if(Test-Path -Path Alias:\igf) { - Remove-Item -Path Alias:\igf - } - if(Test-Path -Path Alias:\igfbackup) { - Rename-Item -Path Alias:\igfbackup -NewName igf - } } It 'Expands a single line command' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { git checkout $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout ' } It 'Expands a single line command with short parameter' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { git checkout -b $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout -b ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout -b ' } It 'Expands a single line command with long parameter' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { git checkout --detach $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout --detach ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout --detach ' } It 'Expands the first line in command' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { git checkout $args $a = 5 Write-Host $null } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout ' } It 'Expands the middle line in command' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { $a = 5 git checkout $args Write-Host $null } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout ' } It 'Expands the last line in command' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { $a = 5 Write-Host $null git checkout $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout ' } It 'Expands semicolon delimited commands' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { $a = 5; git checkout $args; Write-Host $null; } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout ' } It 'Expands mixed semicolon delimited and newline commands' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { $a = 5; Write-Host $null git checkout $args; Write-Host $null; } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout ' } It 'Expands mixed semicolon delimited and newline multiline commands' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { $a = 5; Write-Host $null git ` checkout ` $args; Write-Host $null; } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout ' } It 'Expands simultaneously semicolon delimited and newline commands' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { $a = 5; Write-Host $null; git checkout $args; Write-Host $null; } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout ' } It 'Expands multiline command' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { git ` checkout ` $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout ' } It 'Expands multiline command with short parameter' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { git ` checkout ` -b ` $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout -b ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout -b ' } It 'Expands multiline command with long parameter' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { git ` checkout ` --detach ` $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout --detach ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'git checkout --detach ' } It 'Does not expand command if $args is not present' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { git checkout } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'Invoke-GitFunction ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'igf ' } It 'Does not expand command if $args is not attached to the git command' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { $a = 5 git checkout Write-Host $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'Invoke-GitFunction ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'igf ' } It 'Does not expand multiline command if $args is not attached to the git command' { - function global:Invoke-GitFunction { + function script:Invoke-GitFunction { $a = 5 git ` checkout Write-Host $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'Invoke-GitFunction ' - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'igf ' } } Context 'Proxy Command Parameter Replacement Tests' { @@ -218,9 +161,7 @@ Describe 'Proxy Command Expansion Tests' { if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup } - if(Test-Path -Path Alias:\igf) { - Rename-Item -Path Alias:\igf -NewName igfbackup - } + function script:Invoke-GitFunction { git checkout $args } } AfterEach { if(Test-Path -Path Function:\Invoke-GitFunction) { @@ -229,46 +170,174 @@ Describe 'Proxy Command Expansion Tests' { if(Test-Path -Path Function:\Invoke-GitFunctionBackup) { Rename-Item Function:\Invoke-GitFunctionBackup Invoke-GitFunction } - if(Test-Path -Path Alias:\igf) { - Remove-Item -Path Alias:\igf - } - if(Test-Path -Path Alias:\igfbackup) { - Rename-Item -Path Alias:\igfbackup -NewName igf - } } It 'Replaces parameter in $args' { - function global:Invoke-GitFunction { git checkout $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction master' $result | Should -Be 'git checkout master' - $result = & $module Expand-GitProxyCommand 'igf master' - $result | Should -Be 'git checkout master' } It 'Replaces short parameter in $args' { - function global:Invoke-GitFunction { git checkout $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction -b master' $result | Should -Be 'git checkout -b master' - $result = & $module Expand-GitProxyCommand 'igf -b master' - $result | Should -Be 'git checkout -b master' } It 'Replaces long parameter in $args' { - function global:Invoke-GitFunction { git checkout $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction --detach master' $result | Should -Be 'git checkout --detach master' - $result = & $module Expand-GitProxyCommand 'igf --detach master' - $result | Should -Be 'git checkout --detach master' } It 'Replaces mixed parameters in $args' { - function global:Invoke-GitFunction { git checkout $args } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction -q -f -m --detach master' $result | Should -Be 'git checkout -q -f -m --detach master' - $result = & $module Expand-GitProxyCommand 'igf -q -f -m --detach master' - $result | Should -Be 'git checkout -q -f -m --detach master' } } + Context 'Alias of Proxy Command TabExpansion Tests' { + BeforeEach { + if(Test-Path -Path Function:\Invoke-GitFunction) { + Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup + } + if(Test-Path -Path Alias:\igf) { + Rename-Item -Path Alias:\igf -NewName igfbackup + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' + } + AfterEach { + if(Test-Path -Path Function:\Invoke-GitFunction) { + Remove-Item -Path Function:\Invoke-GitFunction + } + if(Test-Path -Path Function:\Invoke-GitFunctionBackup) { + Rename-Item Function:\Invoke-GitFunctionBackup Invoke-GitFunction + } + if(Test-Path -Path Alias:\igf) { + Remove-Item -Path Alias:\igf + } + if(Test-Path -Path Alias:\igfbackup) { + Rename-Item -Path Alias:\igfbackup -NewName igf + } + } + It 'Expands a single line command' { + function script:Invoke-GitFunction { + git checkout $args + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + } + It 'Expands a single line command with short parameter' { + function script:Invoke-GitFunction { + git checkout -b $args + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands a single line command with long parameter' { + function script:Invoke-GitFunction { + git checkout --detach $args + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands the first line in command' { + function script:Invoke-GitFunction { + git checkout $args + $a = 5 + Write-Host $null + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands the middle line in command' { + function script:Invoke-GitFunction { + $a = 5 + git checkout $args + Write-Host $null + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands the last line in command' { + function script:Invoke-GitFunction { + $a = 5 + Write-Host $null + git checkout $args + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands semicolon delimited commands' { + function script:Invoke-GitFunction { + $a = 5; git checkout $args; Write-Host $null; + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands mixed semicolon delimited and newline commands' { + function script:Invoke-GitFunction { + $a = 5; Write-Host $null + git checkout $args; Write-Host $null; + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands mixed semicolon delimited and newline multiline commands' { + function script:Invoke-GitFunction { + $a = 5; Write-Host $null + git ` + checkout ` + $args; Write-Host $null; + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands simultaneously semicolon delimited and newline commands' { + function script:Invoke-GitFunction { + $a = 5; + Write-Host $null; + git checkout $args; + Write-Host $null; + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands multiline command' { + function script:Invoke-GitFunction { + git ` + checkout ` + $args + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands multiline command with short parameter' { + function script:Invoke-GitFunction { + git ` + checkout ` + -b ` + $args + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Expands multiline command with long parameter' { + function script:Invoke-GitFunction { + git ` + checkout ` + --detach ` + $args + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } + It 'Does not expand command if $args is not present' { + function script:Invoke-GitFunction { + git checkout + } + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'igf ' + } + It 'Does not expand command if $args is not attached to the git command' { + function script:Invoke-GitFunction { + $a = 5 + git checkout + Write-Host $args + } + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'igf ' + } + It 'Does not expand multiline command if $args is not attached to the git command' { + function script:Invoke-GitFunction { + $a = 5 + git ` + checkout + Write-Host $args + } + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'igf ' + } + } Context 'Proxy Subcommand TabExpansion Tests' { BeforeEach { if(Test-Path -Path Function:\Invoke-GitFunction) { @@ -284,14 +353,14 @@ Describe 'Proxy Command Expansion Tests' { } } It 'Tab completes without subcommands' { - function global:Invoke-GitFunction { git whatever $args } + function script:Invoke-GitFunction { git whatever $args } $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result = & $module GitTabExpansionInternal $CommandText $result | Should -Be @() } It 'Tab completes bisect subcommands' { - function global:Invoke-GitFunction { git bisect $args } + function script:Invoke-GitFunction { git bisect $args } $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result = & $module GitTabExpansionInternal $CommandText @@ -306,7 +375,7 @@ Describe 'Proxy Command Expansion Tests' { $result2 -contains 'skip' | Should -Be $true } It 'Tab completes remote subcommands' { - function global:Invoke-GitFunction { git remote $args } + function script:Invoke-GitFunction { git remote $args } $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result = & $module GitTabExpansionInternal $CommandText From 9bfca1ff848762870cca4ecc01a6261d23d41f23 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 20:26:36 -0700 Subject: [PATCH 13/31] Switched to script scoped variable for the git proxy command regular expression. --- src/GitTabExpansion.ps1 | 15 ++++++--------- test/GitProxyCommandExpansion.Tests.ps1 | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index fce9e851d..3bd86398c 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -70,6 +70,10 @@ $script:gitCommandsWithParamValues = $gitParamValues.Keys -join '|' $script:vstsCommandsWithShortParams = $shortVstsParams.Keys -join '|' $script:vstsCommandsWithLongParams = $longVstsParams.Keys -join '|' +# The regular expression here matches commands + $args. Some restrictions on delimiting whitespace +# have been made to disallow newlines in the middle of the command without the backtick (`) character preceding them +$script:GitProxyCommandRegex = return "(^|[|;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|``\r?\n)+\S+)*)(([ \t]|``\r?\n)+\`$args)\s*($|[|;`n])" + try { if ($null -ne (git help -a 2>&1 | Select-String flow)) { $script:someCommands += 'flow' @@ -473,12 +477,6 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { } } -function script:Get-GitProxyCommandRegex() { - # The regular expression here matches commands + $args. Some restrictions on delimiting whitespace - # have been made to disallow newlines in the middle of the command without the backtick (`) character preceding them - return "(^|[|;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|``\r?\n)+\S+)*)(([ \t]|``\r?\n)+\`$args)\s*($|[|;`n])" -} - function Expand-GitProxyCommand($Command) { if ($Command -notmatch '^(?\S+)(?.*)$') { return $Command; @@ -495,8 +493,7 @@ function Expand-GitProxyCommand($Command) { if(Test-Path -Path Function:\$CommandName) { $Definition = Get-Item -Path Function:\$CommandName | Select-Object -ExpandProperty 'Definition' - $DefinitionRegex = Get-GitProxyCommandRegex - if ($Definition -match $DefinitionRegex) { + if ($Definition -match $script:GitProxyCommandRegex) { # Clean up the parameters by removing delimiting whitespace and backtick preceding newlines $Params = $Matches['params'] -replace '`\r?\n', '' -replace '\s+', ' ' return $Matches['cmd'].Trim() + ' ' + $Params.Trim() + ' ' + $Arguments.Trim() @@ -517,7 +514,7 @@ if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { $cmdNames = "git","tgit","gitk" if ($global:GitTabSettings.EnableProxyCommandExpansion) { # Register proxy commands if the expansion is enabled - $cmdNames += Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match (Get-GitProxyCommandRegex) } | Select-Object -ExpandProperty 'Name' + $cmdNames += Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match $script:GitProxyCommandRegex } | Select-Object -ExpandProperty 'Name' } $cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index c4462f26f..b6ef57f78 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -188,7 +188,7 @@ Describe 'Proxy Command Expansion Tests' { $result | Should -Be 'git checkout -q -f -m --detach master' } } - Context 'Alias of Proxy Command TabExpansion Tests' { + Context 'Alias of Proxy Command TabExpansion Tests' { BeforeEach { if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup @@ -337,7 +337,7 @@ Describe 'Proxy Command Expansion Tests' { $result = & $module Expand-GitProxyCommand 'igf ' $result | Should -Be 'igf ' } - } + } Context 'Proxy Subcommand TabExpansion Tests' { BeforeEach { if(Test-Path -Path Function:\Invoke-GitFunction) { From 383189363b64ce8309e77dd23606a6b49c0f286c Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 20:36:25 -0700 Subject: [PATCH 14/31] Fixed a bug in the declaration of the git proxy command regex. --- src/GitTabExpansion.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 3bd86398c..ea4936df8 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -72,7 +72,7 @@ $script:vstsCommandsWithLongParams = $longVstsParams.Keys -join '|' # The regular expression here matches commands + $args. Some restrictions on delimiting whitespace # have been made to disallow newlines in the middle of the command without the backtick (`) character preceding them -$script:GitProxyCommandRegex = return "(^|[|;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|``\r?\n)+\S+)*)(([ \t]|``\r?\n)+\`$args)\s*($|[|;`n])" +$script:GitProxyCommandRegex = "(^|[|;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|``\r?\n)+\S+)*)(([ \t]|``\r?\n)+\`$args)\s*($|[|;`n])" try { if ($null -ne (git help -a 2>&1 | Select-String flow)) { From c6b1c1a9a4a28c10ad5c2f6d0dbe845241aacb0f Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 21:01:36 -0700 Subject: [PATCH 15/31] Disallowed prefix piped commands, since it doesn't make sense. --- src/GitTabExpansion.ps1 | 2 +- test/GitProxyCommandExpansion.Tests.ps1 | 27 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index ea4936df8..2b2a4a9d1 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -72,7 +72,7 @@ $script:vstsCommandsWithLongParams = $longVstsParams.Keys -join '|' # The regular expression here matches commands + $args. Some restrictions on delimiting whitespace # have been made to disallow newlines in the middle of the command without the backtick (`) character preceding them -$script:GitProxyCommandRegex = "(^|[|;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|``\r?\n)+\S+)*)(([ \t]|``\r?\n)+\`$args)\s*($|[|;`n])" +$script:GitProxyCommandRegex = "(^|[;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|``\r?\n)+\S+)*)(([ \t]|``\r?\n)+\`$args)\s*($|[|;`n])" try { if ($null -ne (git help -a 2>&1 | Select-String flow)) { diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index b6ef57f78..4498658ed 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -38,6 +38,13 @@ Describe 'Proxy Command Expansion Tests' { $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout --detach ' } + It 'Expands a single line with piped command suffix' { + function script:Invoke-GitFunction { + git checkout --detach $args | Write-Host + } + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout --detach ' + } It 'Expands the first line in command' { function script:Invoke-GitFunction { git checkout $args @@ -129,6 +136,13 @@ Describe 'Proxy Command Expansion Tests' { $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout --detach ' } + It 'Does not expand a single line with piped command prefix' { + function script:Invoke-GitFunction { + "master" | git checkout --detach $args + } + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'Invoke-GitFunction ' + } It 'Does not expand command if $args is not present' { function script:Invoke-GitFunction { git checkout @@ -230,6 +244,12 @@ Describe 'Proxy Command Expansion Tests' { } & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') } + It 'Expands a single line with piped command suffix' { + function script:Invoke-GitFunction { + git checkout --detach $args | Write-Host + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') + } It 'Expands the first line in command' { function script:Invoke-GitFunction { git checkout $args @@ -318,6 +338,13 @@ Describe 'Proxy Command Expansion Tests' { $result = & $module Expand-GitProxyCommand 'igf ' $result | Should -Be 'igf ' } + It 'Does not expand a single line with piped command prefix' { + function script:Invoke-GitFunction { + "master" | git checkout --detach $args + } + $result = & $module Expand-GitProxyCommand 'igf ' + $result | Should -Be 'igf ' + } It 'Does not expand command if $args is not attached to the git command' { function script:Invoke-GitFunction { $a = 5 From ebf3386a755b1f08cb07a9a3e1eda1a72025e217 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Mon, 22 Jun 2020 21:12:40 -0700 Subject: [PATCH 16/31] Recombined alias tests, since they were duplicates; cleaned up the setup and teardown sections for tests. Updated the alias to use script scope instead of global scope in the tests. --- test/GitProxyCommandExpansion.Tests.ps1 | 203 ++++-------------------- 1 file changed, 32 insertions(+), 171 deletions(-) diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index 4498658ed..1611677b1 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -8,6 +8,10 @@ Describe 'Proxy Command Expansion Tests' { if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup } + if(Test-Path -Path Alias:\igf) { + Rename-Item -Path Alias:\igf -NewName igfbackup + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Script' } AfterEach { if(Test-Path -Path Function:\Invoke-GitFunction) { @@ -16,6 +20,12 @@ Describe 'Proxy Command Expansion Tests' { if(Test-Path -Path Function:\Invoke-GitFunctionBackup) { Rename-Item Function:\Invoke-GitFunctionBackup Invoke-GitFunction } + if(Test-Path -Path Alias:\igf) { + Remove-Item -Path Alias:\igf + } + if(Test-Path -Path Alias:\igfbackup) { + Rename-Item -Path Alias:\igfbackup -NewName igf + } } It 'Expands a single line command' { function script:Invoke-GitFunction { @@ -23,6 +33,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands a single line command with short parameter' { function script:Invoke-GitFunction { @@ -30,6 +41,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout -b ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands a single line command with long parameter' { function script:Invoke-GitFunction { @@ -37,6 +49,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout --detach ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands a single line with piped command suffix' { function script:Invoke-GitFunction { @@ -44,6 +57,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout --detach ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands the first line in command' { function script:Invoke-GitFunction { @@ -53,6 +67,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands the middle line in command' { function script:Invoke-GitFunction { @@ -62,6 +77,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands the last line in command' { function script:Invoke-GitFunction { @@ -71,6 +87,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands semicolon delimited commands' { function script:Invoke-GitFunction { @@ -78,6 +95,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands mixed semicolon delimited and newline commands' { function script:Invoke-GitFunction { @@ -86,6 +104,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands mixed semicolon delimited and newline multiline commands' { function script:Invoke-GitFunction { @@ -96,6 +115,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands simultaneously semicolon delimited and newline commands' { function script:Invoke-GitFunction { @@ -106,6 +126,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands multiline command' { function script:Invoke-GitFunction { @@ -115,6 +136,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands multiline command with short parameter' { function script:Invoke-GitFunction { @@ -125,6 +147,7 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout -b ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Expands multiline command with long parameter' { function script:Invoke-GitFunction { @@ -135,20 +158,21 @@ Describe 'Proxy Command Expansion Tests' { } $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' $result | Should -Be 'git checkout --detach ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } It 'Does not expand a single line with piped command prefix' { function script:Invoke-GitFunction { "master" | git checkout --detach $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' - $result | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' } It 'Does not expand command if $args is not present' { function script:Invoke-GitFunction { git checkout } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' - $result | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' } It 'Does not expand command if $args is not attached to the git command' { function script:Invoke-GitFunction { @@ -156,8 +180,8 @@ Describe 'Proxy Command Expansion Tests' { git checkout Write-Host $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' - $result | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' } It 'Does not expand multiline command if $args is not attached to the git command' { function script:Invoke-GitFunction { @@ -166,8 +190,8 @@ Describe 'Proxy Command Expansion Tests' { checkout Write-Host $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' - $result | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' } } Context 'Proxy Command Parameter Replacement Tests' { @@ -202,169 +226,6 @@ Describe 'Proxy Command Expansion Tests' { $result | Should -Be 'git checkout -q -f -m --detach master' } } - Context 'Alias of Proxy Command TabExpansion Tests' { - BeforeEach { - if(Test-Path -Path Function:\Invoke-GitFunction) { - Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup - } - if(Test-Path -Path Alias:\igf) { - Rename-Item -Path Alias:\igf -NewName igfbackup - } - New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Global' - } - AfterEach { - if(Test-Path -Path Function:\Invoke-GitFunction) { - Remove-Item -Path Function:\Invoke-GitFunction - } - if(Test-Path -Path Function:\Invoke-GitFunctionBackup) { - Rename-Item Function:\Invoke-GitFunctionBackup Invoke-GitFunction - } - if(Test-Path -Path Alias:\igf) { - Remove-Item -Path Alias:\igf - } - if(Test-Path -Path Alias:\igfbackup) { - Rename-Item -Path Alias:\igfbackup -NewName igf - } - } - It 'Expands a single line command' { - function script:Invoke-GitFunction { - git checkout $args - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) - } - It 'Expands a single line command with short parameter' { - function script:Invoke-GitFunction { - git checkout -b $args - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands a single line command with long parameter' { - function script:Invoke-GitFunction { - git checkout --detach $args - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands a single line with piped command suffix' { - function script:Invoke-GitFunction { - git checkout --detach $args | Write-Host - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands the first line in command' { - function script:Invoke-GitFunction { - git checkout $args - $a = 5 - Write-Host $null - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands the middle line in command' { - function script:Invoke-GitFunction { - $a = 5 - git checkout $args - Write-Host $null - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands the last line in command' { - function script:Invoke-GitFunction { - $a = 5 - Write-Host $null - git checkout $args - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands semicolon delimited commands' { - function script:Invoke-GitFunction { - $a = 5; git checkout $args; Write-Host $null; - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands mixed semicolon delimited and newline commands' { - function script:Invoke-GitFunction { - $a = 5; Write-Host $null - git checkout $args; Write-Host $null; - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands mixed semicolon delimited and newline multiline commands' { - function script:Invoke-GitFunction { - $a = 5; Write-Host $null - git ` - checkout ` - $args; Write-Host $null; - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands simultaneously semicolon delimited and newline commands' { - function script:Invoke-GitFunction { - $a = 5; - Write-Host $null; - git checkout $args; - Write-Host $null; - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands multiline command' { - function script:Invoke-GitFunction { - git ` - checkout ` - $args - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands multiline command with short parameter' { - function script:Invoke-GitFunction { - git ` - checkout ` - -b ` - $args - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Expands multiline command with long parameter' { - function script:Invoke-GitFunction { - git ` - checkout ` - --detach ` - $args - } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be (& $module Expand-GitProxyCommand 'igf ') - } - It 'Does not expand command if $args is not present' { - function script:Invoke-GitFunction { - git checkout - } - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'igf ' - } - It 'Does not expand a single line with piped command prefix' { - function script:Invoke-GitFunction { - "master" | git checkout --detach $args - } - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'igf ' - } - It 'Does not expand command if $args is not attached to the git command' { - function script:Invoke-GitFunction { - $a = 5 - git checkout - Write-Host $args - } - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'igf ' - } - It 'Does not expand multiline command if $args is not attached to the git command' { - function script:Invoke-GitFunction { - $a = 5 - git ` - checkout - Write-Host $args - } - $result = & $module Expand-GitProxyCommand 'igf ' - $result | Should -Be 'igf ' - } - } Context 'Proxy Subcommand TabExpansion Tests' { BeforeEach { if(Test-Path -Path Function:\Invoke-GitFunction) { From 541d55adce6257d951b806529a1ae6a047031c82 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Tue, 23 Jun 2020 01:35:55 -0700 Subject: [PATCH 17/31] Added tests to cover more edge cases. Updated the proxy command expansion to pass the new tests. --- src/GitTabExpansion.ps1 | 12 ++-- test/GitProxyCommandExpansion.Tests.ps1 | 76 ++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 2b2a4a9d1..c8a662992 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -72,7 +72,7 @@ $script:vstsCommandsWithLongParams = $longVstsParams.Keys -join '|' # The regular expression here matches commands + $args. Some restrictions on delimiting whitespace # have been made to disallow newlines in the middle of the command without the backtick (`) character preceding them -$script:GitProxyCommandRegex = "(^|[;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|``\r?\n)+\S+)*)(([ \t]|``\r?\n)+\`$args)\s*($|[|;`n])" +$script:GitProxyCommandRegex = "(^|[;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|[ \t]``\r?\n)+\S+)*)(([ \t]|[ \t]``\r?\n)+\`$args)(\s|``\r?\n)*($|[|;`n])" try { if ($null -ne (git help -a 2>&1 | Select-String flow)) { @@ -478,8 +478,8 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { } function Expand-GitProxyCommand($Command) { - if ($Command -notmatch '^(?\S+)(?.*)$') { - return $Command; + if ($Command -notmatch '^(?\S+)(\s|\s`\r?\n)+(?(\s|\s`\r?\n|\S)*)$') { + return $Command } # Store arguments for replacement later @@ -490,13 +490,11 @@ function Expand-GitProxyCommand($Command) { while(Test-Path -Path Alias:\$CommandName) { $CommandName = Get-Item -Path Alias:\$CommandName | Select-Object -ExpandProperty 'ResolvedCommandName' } - if(Test-Path -Path Function:\$CommandName) { $Definition = Get-Item -Path Function:\$CommandName | Select-Object -ExpandProperty 'Definition' if ($Definition -match $script:GitProxyCommandRegex) { - # Clean up the parameters by removing delimiting whitespace and backtick preceding newlines - $Params = $Matches['params'] -replace '`\r?\n', '' -replace '\s+', ' ' - return $Matches['cmd'].Trim() + ' ' + $Params.Trim() + ' ' + $Arguments.Trim() + # Clean up the command by removing extra delimiting whitespace and backtick preceding newlines + return (("$($Matches['cmd'].TrimStart()) $($Matches['params']) $Arguments") -replace '`\r?\n', ' ' -replace '\s+', ' ') } } diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index 1611677b1..73de7563f 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -3,7 +3,59 @@ BeforeAll { } Describe 'Proxy Command Expansion Tests' { - Context 'Proxy Command TabExpansion Tests' { + Context 'Proxy Command Name TabExpansion Tests' { + BeforeEach { + if(Test-Path -Path Function:\Invoke-GitFunction) { + Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup + } + if(Test-Path -Path Alias:\igf) { + Rename-Item -Path Alias:\igf -NewName igfbackup + } + New-Alias -Name 'igf' -Value Invoke-GitFunction -Scope 'Script' + } + AfterEach { + if(Test-Path -Path Function:\Invoke-GitFunction) { + Remove-Item -Path Function:\Invoke-GitFunction + } + if(Test-Path -Path Function:\Invoke-GitFunctionBackup) { + Rename-Item Function:\Invoke-GitFunctionBackup Invoke-GitFunction + } + if(Test-Path -Path Alias:\igf) { + Remove-Item -Path Alias:\igf + } + if(Test-Path -Path Alias:\igfbackup) { + Rename-Item -Path Alias:\igfbackup -NewName igf + } + } + It 'Expands a proxy command with parameters' { + function script:Invoke-GitFunction { git checkout $args } + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction -b newbranch' + $result | Should -Be 'git checkout -b newbranch' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf -b newbranch') + } + It 'Expands a multiline proxy command' { + function script:Invoke-GitFunction { git checkout $args } + $result = & $module Expand-GitProxyCommand "Invoke-GitFunction ```r`n-b ```r`nnewbranch" + $result | Should -Be 'git checkout -b newbranch' + $result | Should -Be (& $module Expand-GitProxyCommand "igf ```r`n-b```r`nnewbranch") + } + It 'Expands a multiline proxy command' { + function script:Invoke-GitFunction { git checkout $args } + & $module Expand-GitProxyCommand "Invoke-GitFunction ```r`n-b ```r`nnewbranch" | Should -Be 'git checkout -b newbranch' + & $module Expand-GitProxyCommand "igf ```r`n-b ```r`nnewbranch" | Should -Be 'git checkout -b newbranch' + } + It 'Does not expand the proxy command name if there is no preceding whitespace before backtick newlines' { + function script:Invoke-GitFunction { git checkout $args } + & $module Expand-GitProxyCommand "Invoke-GitFunction```r`n-b```r`nnewbranch" | Should -Be "Invoke-GitFunction```r`n-b```r`nnewbranch" + & $module Expand-GitProxyCommand "igf```r`n-b```r`nnewbranch" | Should -Be "igf```r`n-b```r`nnewbranch" + } + It 'Does not expand the proxy command if there is no trailing space' { + function script:Invoke-GitFunction { git checkout $args } + & $module Expand-GitProxyCommand 'Invoke-GitFunction' | Should -Be 'Invoke-GitFunction' + & $module Expand-GitProxyCommand 'igf' | Should -Be 'igf' + } + } + Context 'Proxy Command Definition Expansion Tests' { BeforeEach { if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup @@ -138,6 +190,17 @@ Describe 'Proxy Command Expansion Tests' { $result | Should -Be 'git checkout ' $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) } + It 'Expands multiline command that terminates with semicolon on new line' { + function script:Invoke-GitFunction { + git ` + checkout ` + $args ` + ; + } + $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result | Should -Be 'git checkout ' + $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + } It 'Expands multiline command with short parameter' { function script:Invoke-GitFunction { git ` @@ -193,6 +256,17 @@ Describe 'Proxy Command Expansion Tests' { & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' } + It 'Does not expand multiline command backtick newlines are not preceded with whitespace' { + function script:Invoke-GitFunction { + $a = 5 + git` + checkout` + $args + Write-Host $null + } + & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' + } } Context 'Proxy Command Parameter Replacement Tests' { BeforeEach { From cd8aa43fd4ffce697ac9724ad1d1088aff92f41e Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Tue, 23 Jun 2020 01:44:12 -0700 Subject: [PATCH 18/31] Fixed a bug where some parameters without whitespace preceding backtick newlines was accepted. --- src/GitTabExpansion.ps1 | 2 +- test/GitProxyCommandExpansion.Tests.ps1 | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index c8a662992..ecee42606 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -478,7 +478,7 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { } function Expand-GitProxyCommand($Command) { - if ($Command -notmatch '^(?\S+)(\s|\s`\r?\n)+(?(\s|\s`\r?\n|\S)*)$') { + if ($Command -notmatch '^(?\S+)([ \t]|\s`\r?\n)+(?([ \t]|\s`\r?\n|\S)*)$') { return $Command } diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index 73de7563f..f6e1fd883 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -37,7 +37,7 @@ Describe 'Proxy Command Expansion Tests' { function script:Invoke-GitFunction { git checkout $args } $result = & $module Expand-GitProxyCommand "Invoke-GitFunction ```r`n-b ```r`nnewbranch" $result | Should -Be 'git checkout -b newbranch' - $result | Should -Be (& $module Expand-GitProxyCommand "igf ```r`n-b```r`nnewbranch") + $result | Should -Be (& $module Expand-GitProxyCommand "igf ```r`n-b ```r`nnewbranch") } It 'Expands a multiline proxy command' { function script:Invoke-GitFunction { git checkout $args } @@ -49,6 +49,11 @@ Describe 'Proxy Command Expansion Tests' { & $module Expand-GitProxyCommand "Invoke-GitFunction```r`n-b```r`nnewbranch" | Should -Be "Invoke-GitFunction```r`n-b```r`nnewbranch" & $module Expand-GitProxyCommand "igf```r`n-b```r`nnewbranch" | Should -Be "igf```r`n-b```r`nnewbranch" } + It 'Does not expand the proxy command name if there is no preceding whitespace before any backtick newlines' { + function script:Invoke-GitFunction { git checkout $args } + & $module Expand-GitProxyCommand "Invoke-GitFunction ```r`n-b```r`nnewbranch" | Should -Be "Invoke-GitFunction ```r`n-b```r`nnewbranch" + & $module Expand-GitProxyCommand "igf ```r`n-b```r`nnewbranch" | Should -Be "igf ```r`n-b```r`nnewbranch" + } It 'Does not expand the proxy command if there is no trailing space' { function script:Invoke-GitFunction { git checkout $args } & $module Expand-GitProxyCommand 'Invoke-GitFunction' | Should -Be 'Invoke-GitFunction' From 423194bf8b3ea948015d47b001cc495b33688de6 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Tue, 23 Jun 2020 02:13:47 -0700 Subject: [PATCH 19/31] Updated the git proxy command regular expressions to use negative matching [^\S\r\n] to indicate non-newline whitespaces. Added a test that covers newlines preceding backtick newlines. --- src/GitTabExpansion.ps1 | 4 ++-- test/GitProxyCommandExpansion.Tests.ps1 | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index ecee42606..bf772730f 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -72,7 +72,7 @@ $script:vstsCommandsWithLongParams = $longVstsParams.Keys -join '|' # The regular expression here matches commands + $args. Some restrictions on delimiting whitespace # have been made to disallow newlines in the middle of the command without the backtick (`) character preceding them -$script:GitProxyCommandRegex = "(^|[;`n])\s*(?$(Get-AliasPattern git))(?(([ \t]|[ \t]``\r?\n)+\S+)*)(([ \t]|[ \t]``\r?\n)+\`$args)(\s|``\r?\n)*($|[|;`n])" +$script:GitProxyCommandRegex = "(^|[;`n])\s*(?$(Get-AliasPattern git))(?(([^\S\r\n]|[^\S\r\n]``\r?\n)+\S+)*)(([^\S\r\n]|[^\S\r\n]``\r?\n)+\`$args)(\s|``\r?\n)*($|[|;`n])" try { if ($null -ne (git help -a 2>&1 | Select-String flow)) { @@ -478,7 +478,7 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { } function Expand-GitProxyCommand($Command) { - if ($Command -notmatch '^(?\S+)([ \t]|\s`\r?\n)+(?([ \t]|\s`\r?\n|\S)*)$') { + if ($Command -notmatch '^(?\S+)([^\S\r\n]|[^\S\r\n]`\r?\n)+(?([^\S\r\n]|[^\S\r\n]`\r?\n|\S)*)$') { return $Command } diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index f6e1fd883..24b367042 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -49,11 +49,16 @@ Describe 'Proxy Command Expansion Tests' { & $module Expand-GitProxyCommand "Invoke-GitFunction```r`n-b```r`nnewbranch" | Should -Be "Invoke-GitFunction```r`n-b```r`nnewbranch" & $module Expand-GitProxyCommand "igf```r`n-b```r`nnewbranch" | Should -Be "igf```r`n-b```r`nnewbranch" } - It 'Does not expand the proxy command name if there is no preceding whitespace before any backtick newlines' { + It 'Does not expand the proxy command name if there is no preceding non-newline whitespace before any backtick newlines' { function script:Invoke-GitFunction { git checkout $args } & $module Expand-GitProxyCommand "Invoke-GitFunction ```r`n-b```r`nnewbranch" | Should -Be "Invoke-GitFunction ```r`n-b```r`nnewbranch" & $module Expand-GitProxyCommand "igf ```r`n-b```r`nnewbranch" | Should -Be "igf ```r`n-b```r`nnewbranch" } + It 'Does not expand the proxy command name if the preceding whitespace before backtick newlines are newlines' { + function script:Invoke-GitFunction { git checkout $args } + & $module Expand-GitProxyCommand "Invoke-GitFunction`r`n```r`n-b`r`n```r`nnewbranch" | Should -Be "Invoke-GitFunction`r`n```r`n-b`r`n```r`nnewbranch" + & $module Expand-GitProxyCommand "igf`r`n```r`n-b`r`n```r`nnewbranch" | Should -Be "igf`r`n```r`n-b`r`n```r`nnewbranch" + } It 'Does not expand the proxy command if there is no trailing space' { function script:Invoke-GitFunction { git checkout $args } & $module Expand-GitProxyCommand 'Invoke-GitFunction' | Should -Be 'Invoke-GitFunction' From e6ba17aff9a7c2272b1f7a291c5b977d4af254f5 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Tue, 23 Jun 2020 02:38:41 -0700 Subject: [PATCH 20/31] Expanded the comment explaining the git proxy command regular expression. --- src/GitTabExpansion.ps1 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index bf772730f..82994f518 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -70,9 +70,21 @@ $script:gitCommandsWithParamValues = $gitParamValues.Keys -join '|' $script:vstsCommandsWithShortParams = $shortVstsParams.Keys -join '|' $script:vstsCommandsWithLongParams = $longVstsParams.Keys -join '|' -# The regular expression here matches commands + $args. Some restrictions on delimiting whitespace -# have been made to disallow newlines in the middle of the command without the backtick (`) character preceding them -$script:GitProxyCommandRegex = "(^|[;`n])\s*(?$(Get-AliasPattern git))(?(([^\S\r\n]|[^\S\r\n]``\r?\n)+\S+)*)(([^\S\r\n]|[^\S\r\n]``\r?\n)+\`$args)(\s|``\r?\n)*($|[|;`n])" +# The regular expression here is roughly follows this pattern: +# +# *()*+<$args>* +# +# The delimiters inside the parameter list and between some of the elements are non-newline whitespace characters ([^\S\r\n]). +# In those instances, newlines are only allowed if they preceded by a non-newline whitespace character. +# +# Begin anchor (^|[;`n]) +# Whitespace (\s*) +# Git Command (?$(GetAliasPattern git)) +# Parameters (?(([^\S\r\n]|[^\S\r\n]``\r?\n)+\S+)*) +# $args Anchor (([^\S\r\n]|[^\S\r\n]``\r?\n)+\`$args) +# Whitespace (\s|``\r?\n)* +# End Anchor ($|[|;`n]) +$script:GitProxyCommandRegex = "(^|[;`n])(\s*)(?$(Get-AliasPattern git))(?(([^\S\r\n]|[^\S\r\n]``\r?\n)+\S+)*)(([^\S\r\n]|[^\S\r\n]``\r?\n)+\`$args)(\s|``\r?\n)*($|[|;`n])" try { if ($null -ne (git help -a 2>&1 | Select-String flow)) { From 5e21089e2740605cf8a3177d7bfd42e5481e1a7a Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Tue, 23 Jun 2020 20:16:44 -0700 Subject: [PATCH 21/31] Fixed a bug where the git proxy command expansion was not enabled when PowerTab was loaded. --- src/GitTabExpansion.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 82994f518..5dd3ee59b 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -552,6 +552,9 @@ else { $line = $Context.Line $lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart() + if ($global:GitTabSettings.EnableProxyCommandExpansion) { + $lastBlock = Expand-GitProxyCommand($lastBlock) + } $TabExpansionHasOutput.Value = $true WriteTabExpLog "PowerTab expand: '$lastBlock'" Expand-GitCommand $lastBlock From 50b3df9e8c05bde467683945821b42f017ddf94e Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Wed, 24 Jun 2020 10:56:43 -0700 Subject: [PATCH 22/31] Switched to function to enable proxy command expansion. --- src/GitTabExpansion.ps1 | 28 +++++++++++++++++++++------- src/posh-git.psd1 | 1 + src/posh-git.psm1 | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 5dd3ee59b..f5c5ba5b4 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -513,6 +513,27 @@ function Expand-GitProxyCommand($Command) { return $Command } +function Enable-GitProxyCommandExpansion { + if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { + $cmdNames = Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match $script:GitProxyCommandRegex } | Select-Object -ExpandProperty 'Name' + $cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name + + Microsoft.PowerShell.Core\Register-ArgumentCompleter -CommandName $cmdNames -Native -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + + $padLength = $cursorPosition - $commandAst.Extent.StartOffset + $textToComplete = $commandAst.ToString().PadRight($padLength, ' ').Substring(0, $padLength) + $textToComplete = Expand-GitProxyCommand($textToComplete) + + WriteTabExpLog "Expand: command: '$($commandAst.Extent.Text)', padded: '$textToComplete', padlen: $padLength" + Expand-GitCommand $textToComplete + } + } + else { + $global:GitTabSettings.EnableProxyCommandExpansion = $true; + } +} + function WriteTabExpLog([string] $Message) { if (!$global:GitTabSettings.EnableLogging) { return } @@ -522,10 +543,6 @@ function WriteTabExpLog([string] $Message) { if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { $cmdNames = "git","tgit","gitk" - if ($global:GitTabSettings.EnableProxyCommandExpansion) { - # Register proxy commands if the expansion is enabled - $cmdNames += Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match $script:GitProxyCommandRegex } | Select-Object -ExpandProperty 'Name' - } $cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name Microsoft.PowerShell.Core\Register-ArgumentCompleter -CommandName $cmdNames -Native -ScriptBlock { @@ -536,9 +553,6 @@ if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { # The Expand-GitCommand expects this trailing space, so pad with a space if necessary. $padLength = $cursorPosition - $commandAst.Extent.StartOffset $textToComplete = $commandAst.ToString().PadRight($padLength, ' ').Substring(0, $padLength) - if ($global:GitTabSettings.EnableProxyCommandExpansion) { - $textToComplete = Expand-GitProxyCommand($textToComplete) - } WriteTabExpLog "Expand: command: '$($commandAst.Extent.Text)', padded: '$textToComplete', padlen: $padLength" Expand-GitCommand $textToComplete diff --git a/src/posh-git.psd1 b/src/posh-git.psd1 index 0f3587c77..79d523c1a 100644 --- a/src/posh-git.psd1 +++ b/src/posh-git.psd1 @@ -24,6 +24,7 @@ PowerShellVersion = '5.0' # Functions to export from this module FunctionsToExport = @( 'Add-PoshGitToProfile', + 'Enable-GitProxyCommandExpansion', 'Expand-GitCommand', 'Format-GitBranchName', 'Get-GitBranchStatusColor', diff --git a/src/posh-git.psm1 b/src/posh-git.psm1 index df90b0903..c35074a09 100644 --- a/src/posh-git.psm1 +++ b/src/posh-git.psm1 @@ -152,6 +152,7 @@ $ExecutionContext.SessionState.Module.OnRemove = { $exportModuleMemberParams = @{ Function = @( 'Add-PoshGitToProfile', + 'Enable-GitProxyCommandExpansion', 'Expand-GitCommand', 'Format-GitBranchName', 'Get-GitBranchStatusColor', From fa4412ed7bea8d5569913135ca78dd75613deeba Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Thu, 25 Jun 2020 21:18:04 -0700 Subject: [PATCH 23/31] Switched to argument list loading the proxy command expansion variable. --- src/GitTabExpansion.ps1 | 32 ++++++++------------------------ src/posh-git.psd1 | 1 - src/posh-git.psm1 | 3 +-- 3 files changed, 9 insertions(+), 27 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index f5c5ba5b4..9c101a897 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -7,7 +7,6 @@ $Global:GitTabSettings = New-Object PSObject -Property @{ '!f() { exec vsts code pr "$@"; }; f' = 'vsts.pr' } EnableLogging = $false - EnableProxyCommandExpansion = $false LogPath = Join-Path ([System.IO.Path]::GetTempPath()) posh-git_tabexp.log } @@ -513,27 +512,6 @@ function Expand-GitProxyCommand($Command) { return $Command } -function Enable-GitProxyCommandExpansion { - if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { - $cmdNames = Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match $script:GitProxyCommandRegex } | Select-Object -ExpandProperty 'Name' - $cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name - - Microsoft.PowerShell.Core\Register-ArgumentCompleter -CommandName $cmdNames -Native -ScriptBlock { - param($wordToComplete, $commandAst, $cursorPosition) - - $padLength = $cursorPosition - $commandAst.Extent.StartOffset - $textToComplete = $commandAst.ToString().PadRight($padLength, ' ').Substring(0, $padLength) - $textToComplete = Expand-GitProxyCommand($textToComplete) - - WriteTabExpLog "Expand: command: '$($commandAst.Extent.Text)', padded: '$textToComplete', padlen: $padLength" - Expand-GitCommand $textToComplete - } - } - else { - $global:GitTabSettings.EnableProxyCommandExpansion = $true; - } -} - function WriteTabExpLog([string] $Message) { if (!$global:GitTabSettings.EnableLogging) { return } @@ -543,6 +521,9 @@ function WriteTabExpLog([string] $Message) { if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { $cmdNames = "git","tgit","gitk" + if ($EnableProxyCommandExpansion) { + $cmdNames += Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match $script:GitProxyCommandRegex } | Select-Object -ExpandProperty 'Name' + } $cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name Microsoft.PowerShell.Core\Register-ArgumentCompleter -CommandName $cmdNames -Native -ScriptBlock { @@ -553,6 +534,9 @@ if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { # The Expand-GitCommand expects this trailing space, so pad with a space if necessary. $padLength = $cursorPosition - $commandAst.Extent.StartOffset $textToComplete = $commandAst.ToString().PadRight($padLength, ' ').Substring(0, $padLength) + if ($EnableProxyCommandExpansion) { + $textToComplete = Expand-GitProxyCommand($textToComplete) + } WriteTabExpLog "Expand: command: '$($commandAst.Extent.Text)', padded: '$textToComplete', padlen: $padLength" Expand-GitCommand $textToComplete @@ -566,7 +550,7 @@ else { $line = $Context.Line $lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart() - if ($global:GitTabSettings.EnableProxyCommandExpansion) { + if ($EnableProxyCommandExpansion) { $lastBlock = Expand-GitProxyCommand($lastBlock) } $TabExpansionHasOutput.Value = $true @@ -579,7 +563,7 @@ else { function TabExpansion($line, $lastWord) { $lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart() - if ($global:GitTabSettings.EnableProxyCommandExpansion) { + if ($EnableProxyCommandExpansion) { $lastBlock = Expand-GitProxyCommand($lastBlock) } $msg = "Legacy expand: '$lastBlock'" diff --git a/src/posh-git.psd1 b/src/posh-git.psd1 index 79d523c1a..0f3587c77 100644 --- a/src/posh-git.psd1 +++ b/src/posh-git.psd1 @@ -24,7 +24,6 @@ PowerShellVersion = '5.0' # Functions to export from this module FunctionsToExport = @( 'Add-PoshGitToProfile', - 'Enable-GitProxyCommandExpansion', 'Expand-GitCommand', 'Format-GitBranchName', 'Get-GitBranchStatusColor', diff --git a/src/posh-git.psm1 b/src/posh-git.psm1 index c35074a09..1f4e92243 100644 --- a/src/posh-git.psm1 +++ b/src/posh-git.psm1 @@ -1,4 +1,4 @@ -param([bool]$ForcePoshGitPrompt, [bool]$UseLegacyTabExpansion) +param([bool]$ForcePoshGitPrompt, [bool]$UseLegacyTabExpansion, [bool]$EnableProxyCommandExpansion) . $PSScriptRoot\CheckRequirements.ps1 > $null @@ -152,7 +152,6 @@ $ExecutionContext.SessionState.Module.OnRemove = { $exportModuleMemberParams = @{ Function = @( 'Add-PoshGitToProfile', - 'Enable-GitProxyCommandExpansion', 'Expand-GitCommand', 'Format-GitBranchName', 'Get-GitBranchStatusColor', From 36fc9866f9af4fb494cab651bd6e994369f62014 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Fri, 26 Jun 2020 19:40:08 -0700 Subject: [PATCH 24/31] Removed a duplicate test. --- test/GitProxyCommandExpansion.Tests.ps1 | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index 24b367042..873acd14c 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -39,11 +39,6 @@ Describe 'Proxy Command Expansion Tests' { $result | Should -Be 'git checkout -b newbranch' $result | Should -Be (& $module Expand-GitProxyCommand "igf ```r`n-b ```r`nnewbranch") } - It 'Expands a multiline proxy command' { - function script:Invoke-GitFunction { git checkout $args } - & $module Expand-GitProxyCommand "Invoke-GitFunction ```r`n-b ```r`nnewbranch" | Should -Be 'git checkout -b newbranch' - & $module Expand-GitProxyCommand "igf ```r`n-b ```r`nnewbranch" | Should -Be 'git checkout -b newbranch' - } It 'Does not expand the proxy command name if there is no preceding whitespace before backtick newlines' { function script:Invoke-GitFunction { git checkout $args } & $module Expand-GitProxyCommand "Invoke-GitFunction```r`n-b```r`nnewbranch" | Should -Be "Invoke-GitFunction```r`n-b```r`nnewbranch" From 8492243e238a2d35ea976dc4ceeb3f61482b04e3 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Fri, 31 Jul 2020 23:47:53 -0700 Subject: [PATCH 25/31] Added some comments to explain the Expand-GitProxyCommand function> --- src/GitTabExpansion.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 9c101a897..b81db2fee 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -489,6 +489,8 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { } function Expand-GitProxyCommand($Command) { + # Make sure the incoming command matches: , so we can extract the alias/command + # name and the arguments being passed in. if ($Command -notmatch '^(?\S+)([^\S\r\n]|[^\S\r\n]`\r?\n)+(?([^\S\r\n]|[^\S\r\n]`\r?\n|\S)*)$') { return $Command } @@ -501,6 +503,8 @@ function Expand-GitProxyCommand($Command) { while(Test-Path -Path Alias:\$CommandName) { $CommandName = Get-Item -Path Alias:\$CommandName | Select-Object -ExpandProperty 'ResolvedCommandName' } + + # Extract definition of git usage if(Test-Path -Path Function:\$CommandName) { $Definition = Get-Item -Path Function:\$CommandName | Select-Object -ExpandProperty 'Definition' if ($Definition -match $script:GitProxyCommandRegex) { From 559cd58b782529d462486f473f7a16ac22cd7a61 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Fri, 31 Jul 2020 23:50:23 -0700 Subject: [PATCH 26/31] Switched to an if statement to check for aliases, because the ResolvedCommandName property already traverses the alias chain. --- src/GitTabExpansion.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index b81db2fee..3a201fae6 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -498,9 +498,9 @@ function Expand-GitProxyCommand($Command) { # Store arguments for replacement later $Arguments = $Matches['args'] - # Traverse alias chain to command name + # Get the command name; if an alias exists, get the actual command name $CommandName = $Matches['command'] - while(Test-Path -Path Alias:\$CommandName) { + if(Test-Path -Path Alias:\$CommandName) { $CommandName = Get-Item -Path Alias:\$CommandName | Select-Object -ExpandProperty 'ResolvedCommandName' } From 7d283ca669412efbc135ab893973f61238066128 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Sun, 6 Sep 2020 13:25:31 -0700 Subject: [PATCH 27/31] Switched to camel casing for local scope variables. --- src/GitTabExpansion.ps1 | 24 ++++++++++++------------ test/GitProxyCommandExpansion.Tests.ps1 | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 3a201fae6..4c4ae1835 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -488,32 +488,32 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { } } -function Expand-GitProxyCommand($Command) { +function Expand-GitProxyCommand($command) { # Make sure the incoming command matches: , so we can extract the alias/command # name and the arguments being passed in. - if ($Command -notmatch '^(?\S+)([^\S\r\n]|[^\S\r\n]`\r?\n)+(?([^\S\r\n]|[^\S\r\n]`\r?\n|\S)*)$') { - return $Command + if ($command -notmatch '^(?\S+)([^\S\r\n]|[^\S\r\n]`\r?\n)+(?([^\S\r\n]|[^\S\r\n]`\r?\n|\S)*)$') { + return $command } # Store arguments for replacement later - $Arguments = $Matches['args'] + $arguments = $matches['args'] # Get the command name; if an alias exists, get the actual command name - $CommandName = $Matches['command'] - if(Test-Path -Path Alias:\$CommandName) { - $CommandName = Get-Item -Path Alias:\$CommandName | Select-Object -ExpandProperty 'ResolvedCommandName' + $commandName = $matches['command'] + if(Test-Path -Path Alias:\$commandName) { + $commandName = Get-Item -Path Alias:\$commandName | Select-Object -ExpandProperty 'ResolvedCommandName' } # Extract definition of git usage - if(Test-Path -Path Function:\$CommandName) { - $Definition = Get-Item -Path Function:\$CommandName | Select-Object -ExpandProperty 'Definition' - if ($Definition -match $script:GitProxyCommandRegex) { + if(Test-Path -Path Function:\$commandName) { + $definition = Get-Item -Path Function:\$commandName | Select-Object -ExpandProperty 'Definition' + if ($definition -match $script:GitProxyCommandRegex) { # Clean up the command by removing extra delimiting whitespace and backtick preceding newlines - return (("$($Matches['cmd'].TrimStart()) $($Matches['params']) $Arguments") -replace '`\r?\n', ' ' -replace '\s+', ' ') + return (("$($matches['cmd'].TrimStart()) $($matches['params']) $arguments") -replace '`\r?\n', ' ' -replace '\s+', ' ') } } - return $Command + return $command } function WriteTabExpLog([string] $Message) { diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyCommandExpansion.Tests.ps1 index 873acd14c..65307f9d1 100644 --- a/test/GitProxyCommandExpansion.Tests.ps1 +++ b/test/GitProxyCommandExpansion.Tests.ps1 @@ -321,30 +321,30 @@ Describe 'Proxy Command Expansion Tests' { } It 'Tab completes without subcommands' { function script:Invoke-GitFunction { git whatever $args } - $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' - $result = & $module GitTabExpansionInternal $CommandText + $commandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module GitTabExpansionInternal $commandText $result | Should -Be @() } It 'Tab completes bisect subcommands' { function script:Invoke-GitFunction { git bisect $args } - $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' - $result = & $module GitTabExpansionInternal $CommandText + $commandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module GitTabExpansionInternal $commandText $result -contains '' | Should -Be $false $result -contains 'start' | Should -Be $true $result -contains 'run' | Should -Be $true - $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction s' - $result2 = & $module GitTabExpansionInternal $CommandText + $commandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction s' + $result2 = & $module GitTabExpansionInternal $commandText $result2 -contains 'start' | Should -Be $true $result2 -contains 'skip' | Should -Be $true } It 'Tab completes remote subcommands' { function script:Invoke-GitFunction { git remote $args } - $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' - $result = & $module GitTabExpansionInternal $CommandText + $commandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module GitTabExpansionInternal $commandText $result -contains '' | Should -Be $false $result -contains 'add' | Should -Be $true @@ -352,8 +352,8 @@ Describe 'Proxy Command Expansion Tests' { $result -contains 'get-url' | Should -Be $true $result -contains 'update' | Should -Be $true - $CommandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction s' - $result2 = & $module GitTabExpansionInternal $CommandText + $commandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction s' + $result2 = & $module GitTabExpansionInternal $commandText $result2 -contains 'set-branches' | Should -Be $true $result2 -contains 'set-head' | Should -Be $true From d6bfb5a142c45423f465aa4a2efd832b568bac32 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Sun, 6 Sep 2020 13:50:23 -0700 Subject: [PATCH 28/31] Fixed some formatting. --- src/GitTabExpansion.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 4c4ae1835..0e4f01043 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -500,12 +500,12 @@ function Expand-GitProxyCommand($command) { # Get the command name; if an alias exists, get the actual command name $commandName = $matches['command'] - if(Test-Path -Path Alias:\$commandName) { + if (Test-Path -Path Alias:\$commandName) { $commandName = Get-Item -Path Alias:\$commandName | Select-Object -ExpandProperty 'ResolvedCommandName' } # Extract definition of git usage - if(Test-Path -Path Function:\$commandName) { + if (Test-Path -Path Function:\$commandName) { $definition = Get-Item -Path Function:\$commandName | Select-Object -ExpandProperty 'Definition' if ($definition -match $script:GitProxyCommandRegex) { # Clean up the command by removing extra delimiting whitespace and backtick preceding newlines From a09ae8c450b30559777c357d3f6a4ff23014b6b8 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Sat, 12 Sep 2020 12:58:49 -0700 Subject: [PATCH 29/31] Renamed variables from GitProxyCommand* to GitProxyFunction* to disambiguate between PowerShell's official Proxy Command system. --- src/GitTabExpansion.ps1 | 22 +++++++++++----------- src/posh-git.psm1 | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 0e4f01043..5d46fc446 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -83,7 +83,7 @@ $script:vstsCommandsWithLongParams = $longVstsParams.Keys -join '|' # $args Anchor (([^\S\r\n]|[^\S\r\n]``\r?\n)+\`$args) # Whitespace (\s|``\r?\n)* # End Anchor ($|[|;`n]) -$script:GitProxyCommandRegex = "(^|[;`n])(\s*)(?$(Get-AliasPattern git))(?(([^\S\r\n]|[^\S\r\n]``\r?\n)+\S+)*)(([^\S\r\n]|[^\S\r\n]``\r?\n)+\`$args)(\s|``\r?\n)*($|[|;`n])" +$script:GitProxyFunctionRegex = "(^|[;`n])(\s*)(?$(Get-AliasPattern git))(?(([^\S\r\n]|[^\S\r\n]``\r?\n)+\S+)*)(([^\S\r\n]|[^\S\r\n]``\r?\n)+\`$args)(\s|``\r?\n)*($|[|;`n])" try { if ($null -ne (git help -a 2>&1 | Select-String flow)) { @@ -488,7 +488,7 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { } } -function Expand-GitProxyCommand($command) { +function Expand-GitProxyFunction($command) { # Make sure the incoming command matches: , so we can extract the alias/command # name and the arguments being passed in. if ($command -notmatch '^(?\S+)([^\S\r\n]|[^\S\r\n]`\r?\n)+(?([^\S\r\n]|[^\S\r\n]`\r?\n|\S)*)$') { @@ -507,7 +507,7 @@ function Expand-GitProxyCommand($command) { # Extract definition of git usage if (Test-Path -Path Function:\$commandName) { $definition = Get-Item -Path Function:\$commandName | Select-Object -ExpandProperty 'Definition' - if ($definition -match $script:GitProxyCommandRegex) { + if ($definition -match $script:GitProxyFunctionRegex) { # Clean up the command by removing extra delimiting whitespace and backtick preceding newlines return (("$($matches['cmd'].TrimStart()) $($matches['params']) $arguments") -replace '`\r?\n', ' ' -replace '\s+', ' ') } @@ -525,8 +525,8 @@ function WriteTabExpLog([string] $Message) { if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { $cmdNames = "git","tgit","gitk" - if ($EnableProxyCommandExpansion) { - $cmdNames += Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match $script:GitProxyCommandRegex } | Select-Object -ExpandProperty 'Name' + if ($EnableProxyFunctionExpansion) { + $cmdNames += Get-ChildItem -Path Function:\ | Where-Object { $_.Definition -match $script:GitProxyFunctionRegex } | Select-Object -ExpandProperty 'Name' } $cmdNames += Get-Alias -Definition $cmdNames -ErrorAction Ignore | ForEach-Object Name @@ -538,8 +538,8 @@ if (!$UseLegacyTabExpansion -and ($PSVersionTable.PSVersion.Major -ge 6)) { # The Expand-GitCommand expects this trailing space, so pad with a space if necessary. $padLength = $cursorPosition - $commandAst.Extent.StartOffset $textToComplete = $commandAst.ToString().PadRight($padLength, ' ').Substring(0, $padLength) - if ($EnableProxyCommandExpansion) { - $textToComplete = Expand-GitProxyCommand($textToComplete) + if ($EnableProxyFunctionExpansion) { + $textToComplete = Expand-GitProxyFunction($textToComplete) } WriteTabExpLog "Expand: command: '$($commandAst.Extent.Text)', padded: '$textToComplete', padlen: $padLength" @@ -554,8 +554,8 @@ else { $line = $Context.Line $lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart() - if ($EnableProxyCommandExpansion) { - $lastBlock = Expand-GitProxyCommand($lastBlock) + if ($EnableProxyFunctionExpansion) { + $lastBlock = Expand-GitProxyFunction($lastBlock) } $TabExpansionHasOutput.Value = $true WriteTabExpLog "PowerTab expand: '$lastBlock'" @@ -567,8 +567,8 @@ else { function TabExpansion($line, $lastWord) { $lastBlock = [regex]::Split($line, '[|;]')[-1].TrimStart() - if ($EnableProxyCommandExpansion) { - $lastBlock = Expand-GitProxyCommand($lastBlock) + if ($EnableProxyFunctionExpansion) { + $lastBlock = Expand-GitProxyFunction($lastBlock) } $msg = "Legacy expand: '$lastBlock'" diff --git a/src/posh-git.psm1 b/src/posh-git.psm1 index 1f4e92243..900a502f5 100644 --- a/src/posh-git.psm1 +++ b/src/posh-git.psm1 @@ -1,4 +1,4 @@ -param([bool]$ForcePoshGitPrompt, [bool]$UseLegacyTabExpansion, [bool]$EnableProxyCommandExpansion) +param([bool]$ForcePoshGitPrompt, [bool]$UseLegacyTabExpansion, [bool]$EnableProxyFunctionExpansion) . $PSScriptRoot\CheckRequirements.ps1 > $null From fec371f57aceaf050ed60e0759ecdb2012fda610 Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Sat, 12 Sep 2020 13:00:01 -0700 Subject: [PATCH 30/31] Renamed the GitProxyCommandExpansion.Tests.ps1 test file to GitProxyFunctionExpansion.Tests.ps1. --- ...andExpansion.Tests.ps1 => GitProxyFunctionExpansion.Tests.ps1} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{GitProxyCommandExpansion.Tests.ps1 => GitProxyFunctionExpansion.Tests.ps1} (100%) diff --git a/test/GitProxyCommandExpansion.Tests.ps1 b/test/GitProxyFunctionExpansion.Tests.ps1 similarity index 100% rename from test/GitProxyCommandExpansion.Tests.ps1 rename to test/GitProxyFunctionExpansion.Tests.ps1 From bebace611af4c2df79b61f4de85080b81e08b0fa Mon Sep 17 00:00:00 2001 From: Constantine Chen Date: Sat, 12 Sep 2020 13:12:12 -0700 Subject: [PATCH 31/31] Updated the proxy function tests to reflect the rename from *ProxyCommand* to *ProxyFunction*. --- test/GitProxyFunctionExpansion.Tests.ps1 | 192 +++++++++++------------ 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/test/GitProxyFunctionExpansion.Tests.ps1 b/test/GitProxyFunctionExpansion.Tests.ps1 index 65307f9d1..9ef606db7 100644 --- a/test/GitProxyFunctionExpansion.Tests.ps1 +++ b/test/GitProxyFunctionExpansion.Tests.ps1 @@ -2,8 +2,8 @@ BeforeAll { . $PSScriptRoot\Shared.ps1 } -Describe 'Proxy Command Expansion Tests' { - Context 'Proxy Command Name TabExpansion Tests' { +Describe 'Proxy Function Expansion Tests' { + Context 'Proxy Function Name TabExpansion Tests' { BeforeEach { if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup @@ -27,40 +27,40 @@ Describe 'Proxy Command Expansion Tests' { Rename-Item -Path Alias:\igfbackup -NewName igf } } - It 'Expands a proxy command with parameters' { + It 'Expands a proxy function with parameters' { function script:Invoke-GitFunction { git checkout $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction -b newbranch' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction -b newbranch' $result | Should -Be 'git checkout -b newbranch' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf -b newbranch') + $result | Should -Be (& $module Expand-GitProxyFunction 'igf -b newbranch') } - It 'Expands a multiline proxy command' { + It 'Expands a multiline proxy function' { function script:Invoke-GitFunction { git checkout $args } - $result = & $module Expand-GitProxyCommand "Invoke-GitFunction ```r`n-b ```r`nnewbranch" + $result = & $module Expand-GitProxyFunction "Invoke-GitFunction ```r`n-b ```r`nnewbranch" $result | Should -Be 'git checkout -b newbranch' - $result | Should -Be (& $module Expand-GitProxyCommand "igf ```r`n-b ```r`nnewbranch") + $result | Should -Be (& $module Expand-GitProxyFunction "igf ```r`n-b ```r`nnewbranch") } - It 'Does not expand the proxy command name if there is no preceding whitespace before backtick newlines' { + It 'Does not expand the proxy function name if there is no preceding whitespace before backtick newlines' { function script:Invoke-GitFunction { git checkout $args } - & $module Expand-GitProxyCommand "Invoke-GitFunction```r`n-b```r`nnewbranch" | Should -Be "Invoke-GitFunction```r`n-b```r`nnewbranch" - & $module Expand-GitProxyCommand "igf```r`n-b```r`nnewbranch" | Should -Be "igf```r`n-b```r`nnewbranch" + & $module Expand-GitProxyFunction "Invoke-GitFunction```r`n-b```r`nnewbranch" | Should -Be "Invoke-GitFunction```r`n-b```r`nnewbranch" + & $module Expand-GitProxyFunction "igf```r`n-b```r`nnewbranch" | Should -Be "igf```r`n-b```r`nnewbranch" } - It 'Does not expand the proxy command name if there is no preceding non-newline whitespace before any backtick newlines' { + It 'Does not expand the proxy function name if there is no preceding non-newline whitespace before any backtick newlines' { function script:Invoke-GitFunction { git checkout $args } - & $module Expand-GitProxyCommand "Invoke-GitFunction ```r`n-b```r`nnewbranch" | Should -Be "Invoke-GitFunction ```r`n-b```r`nnewbranch" - & $module Expand-GitProxyCommand "igf ```r`n-b```r`nnewbranch" | Should -Be "igf ```r`n-b```r`nnewbranch" + & $module Expand-GitProxyFunction "Invoke-GitFunction ```r`n-b```r`nnewbranch" | Should -Be "Invoke-GitFunction ```r`n-b```r`nnewbranch" + & $module Expand-GitProxyFunction "igf ```r`n-b```r`nnewbranch" | Should -Be "igf ```r`n-b```r`nnewbranch" } - It 'Does not expand the proxy command name if the preceding whitespace before backtick newlines are newlines' { + It 'Does not expand the proxy function name if the preceding whitespace before backtick newlines are newlines' { function script:Invoke-GitFunction { git checkout $args } - & $module Expand-GitProxyCommand "Invoke-GitFunction`r`n```r`n-b`r`n```r`nnewbranch" | Should -Be "Invoke-GitFunction`r`n```r`n-b`r`n```r`nnewbranch" - & $module Expand-GitProxyCommand "igf`r`n```r`n-b`r`n```r`nnewbranch" | Should -Be "igf`r`n```r`n-b`r`n```r`nnewbranch" + & $module Expand-GitProxyFunction "Invoke-GitFunction`r`n```r`n-b`r`n```r`nnewbranch" | Should -Be "Invoke-GitFunction`r`n```r`n-b`r`n```r`nnewbranch" + & $module Expand-GitProxyFunction "igf`r`n```r`n-b`r`n```r`nnewbranch" | Should -Be "igf`r`n```r`n-b`r`n```r`nnewbranch" } - It 'Does not expand the proxy command if there is no trailing space' { + It 'Does not expand the proxy function if there is no trailing space' { function script:Invoke-GitFunction { git checkout $args } - & $module Expand-GitProxyCommand 'Invoke-GitFunction' | Should -Be 'Invoke-GitFunction' - & $module Expand-GitProxyCommand 'igf' | Should -Be 'igf' + & $module Expand-GitProxyFunction 'Invoke-GitFunction' | Should -Be 'Invoke-GitFunction' + & $module Expand-GitProxyFunction 'igf' | Should -Be 'igf' } } - Context 'Proxy Command Definition Expansion Tests' { + Context 'Proxy Function Definition Expansion Tests' { BeforeEach { if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup @@ -84,184 +84,184 @@ Describe 'Proxy Command Expansion Tests' { Rename-Item -Path Alias:\igfbackup -NewName igf } } - It 'Expands a single line command' { + It 'Expands a single line function' { function script:Invoke-GitFunction { git checkout $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands a single line command with short parameter' { + It 'Expands a single line function with short parameter' { function script:Invoke-GitFunction { git checkout -b $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout -b ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands a single line command with long parameter' { + It 'Expands a single line function with long parameter' { function script:Invoke-GitFunction { git checkout --detach $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout --detach ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands a single line with piped command suffix' { + It 'Expands a single line with piped function suffix' { function script:Invoke-GitFunction { git checkout --detach $args | Write-Host } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout --detach ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands the first line in command' { + It 'Expands the first line in function' { function script:Invoke-GitFunction { git checkout $args $a = 5 Write-Host $null } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands the middle line in command' { + It 'Expands the middle line in function' { function script:Invoke-GitFunction { $a = 5 git checkout $args Write-Host $null } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands the last line in command' { + It 'Expands the last line in function' { function script:Invoke-GitFunction { $a = 5 Write-Host $null git checkout $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands semicolon delimited commands' { + It 'Expands semicolon delimited functions' { function script:Invoke-GitFunction { $a = 5; git checkout $args; Write-Host $null; } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands mixed semicolon delimited and newline commands' { + It 'Expands mixed semicolon delimited and newline functions' { function script:Invoke-GitFunction { $a = 5; Write-Host $null git checkout $args; Write-Host $null; } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands mixed semicolon delimited and newline multiline commands' { + It 'Expands mixed semicolon delimited and newline multiline functions' { function script:Invoke-GitFunction { $a = 5; Write-Host $null git ` checkout ` $args; Write-Host $null; } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands simultaneously semicolon delimited and newline commands' { + It 'Expands simultaneously semicolon delimited and newline functions' { function script:Invoke-GitFunction { $a = 5; Write-Host $null; git checkout $args; Write-Host $null; } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands multiline command' { + It 'Expands multiline function' { function script:Invoke-GitFunction { git ` checkout ` $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands multiline command that terminates with semicolon on new line' { + It 'Expands multiline function that terminates with semicolon on new line' { function script:Invoke-GitFunction { git ` checkout ` $args ` ; } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands multiline command with short parameter' { + It 'Expands multiline function with short parameter' { function script:Invoke-GitFunction { git ` checkout ` -b ` $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout -b ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Expands multiline command with long parameter' { + It 'Expands multiline function with long parameter' { function script:Invoke-GitFunction { git ` checkout ` --detach ` $args } - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' $result | Should -Be 'git checkout --detach ' - $result | Should -Be (& $module Expand-GitProxyCommand 'igf ' ) + $result | Should -Be (& $module Expand-GitProxyFunction 'igf ' ) } - It 'Does not expand a single line with piped command prefix' { + It 'Does not expand a single line with piped function prefix' { function script:Invoke-GitFunction { "master" | git checkout --detach $args } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' - & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' + & $module Expand-GitProxyFunction 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyFunction 'igf ' | Should -Be 'igf ' } - It 'Does not expand command if $args is not present' { + It 'Does not expand function if $args is not present' { function script:Invoke-GitFunction { git checkout } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' - & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' + & $module Expand-GitProxyFunction 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyFunction 'igf ' | Should -Be 'igf ' } - It 'Does not expand command if $args is not attached to the git command' { + It 'Does not expand function if $args is not attached to the git function' { function script:Invoke-GitFunction { $a = 5 git checkout Write-Host $args } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' - & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' + & $module Expand-GitProxyFunction 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyFunction 'igf ' | Should -Be 'igf ' } - It 'Does not expand multiline command if $args is not attached to the git command' { + It 'Does not expand multiline function if $args is not attached to the git function' { function script:Invoke-GitFunction { $a = 5 git ` checkout Write-Host $args } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' - & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' + & $module Expand-GitProxyFunction 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyFunction 'igf ' | Should -Be 'igf ' } - It 'Does not expand multiline command backtick newlines are not preceded with whitespace' { + It 'Does not expand multiline function backtick newlines are not preceded with whitespace' { function script:Invoke-GitFunction { $a = 5 git` @@ -269,11 +269,11 @@ Describe 'Proxy Command Expansion Tests' { $args Write-Host $null } - & $module Expand-GitProxyCommand 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' - & $module Expand-GitProxyCommand 'igf ' | Should -Be 'igf ' + & $module Expand-GitProxyFunction 'Invoke-GitFunction ' | Should -Be 'Invoke-GitFunction ' + & $module Expand-GitProxyFunction 'igf ' | Should -Be 'igf ' } } - Context 'Proxy Command Parameter Replacement Tests' { + Context 'Proxy Function Parameter Replacement Tests' { BeforeEach { if(Test-Path -Path Function:\Invoke-GitFunction) { Rename-Item -Path Function:\Invoke-GitFunction -NewName Invoke-GitFunctionBackup @@ -289,19 +289,19 @@ Describe 'Proxy Command Expansion Tests' { } } It 'Replaces parameter in $args' { - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction master' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction master' $result | Should -Be 'git checkout master' } It 'Replaces short parameter in $args' { - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction -b master' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction -b master' $result | Should -Be 'git checkout -b master' } It 'Replaces long parameter in $args' { - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction --detach master' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction --detach master' $result | Should -Be 'git checkout --detach master' } It 'Replaces mixed parameters in $args' { - $result = & $module Expand-GitProxyCommand 'Invoke-GitFunction -q -f -m --detach master' + $result = & $module Expand-GitProxyFunction 'Invoke-GitFunction -q -f -m --detach master' $result | Should -Be 'git checkout -q -f -m --detach master' } } @@ -321,30 +321,30 @@ Describe 'Proxy Command Expansion Tests' { } It 'Tab completes without subcommands' { function script:Invoke-GitFunction { git whatever $args } - $commandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' - $result = & $module GitTabExpansionInternal $commandText + $functionText = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' + $result = & $module GitTabExpansionInternal $functionText $result | Should -Be @() } It 'Tab completes bisect subcommands' { function script:Invoke-GitFunction { git bisect $args } - $commandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' - $result = & $module GitTabExpansionInternal $commandText + $functionText = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' + $result = & $module GitTabExpansionInternal $functionText $result -contains '' | Should -Be $false $result -contains 'start' | Should -Be $true $result -contains 'run' | Should -Be $true - $commandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction s' - $result2 = & $module GitTabExpansionInternal $commandText + $functionText = & $module Expand-GitProxyFunction 'Invoke-GitFunction s' + $result2 = & $module GitTabExpansionInternal $functionText $result2 -contains 'start' | Should -Be $true $result2 -contains 'skip' | Should -Be $true } It 'Tab completes remote subcommands' { function script:Invoke-GitFunction { git remote $args } - $commandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction ' - $result = & $module GitTabExpansionInternal $commandText + $functionText = & $module Expand-GitProxyFunction 'Invoke-GitFunction ' + $result = & $module GitTabExpansionInternal $functionText $result -contains '' | Should -Be $false $result -contains 'add' | Should -Be $true @@ -352,8 +352,8 @@ Describe 'Proxy Command Expansion Tests' { $result -contains 'get-url' | Should -Be $true $result -contains 'update' | Should -Be $true - $commandText = & $module Expand-GitProxyCommand 'Invoke-GitFunction s' - $result2 = & $module GitTabExpansionInternal $commandText + $functionText = & $module Expand-GitProxyFunction 'Invoke-GitFunction s' + $result2 = & $module GitTabExpansionInternal $functionText $result2 -contains 'set-branches' | Should -Be $true $result2 -contains 'set-head' | Should -Be $true