diff --git a/.vscode/launch.json b/.vscode/launch.json index 6883bec3a..b4827d5d1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,6 +1,18 @@ { "version": "0.2.0", "configurations": [ + { + "type": "PowerShell", + "request": "launch", + "name": "PowerShell Interactive Session" + }, + { + "type": "PowerShell", + "request": "attach", + "name": "PowerShell Attach to Host Process", + "processId": "${command.PickPSHostProcess}", + "runspaceId": 1 + }, { "type": "PowerShell", "request": "launch", @@ -10,4 +22,4 @@ "cwd": "${file}" } ] -} \ No newline at end of file +} diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 61a1de9a8..c8784d465 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -29,8 +29,7 @@ $gitflowsubcommands = @{ } function script:gitCmdOperations($commands, $command, $filter) { - $commands.$command -split ' ' | - Where-Object { $_ -like "$filter*" } + $commands.$command -split ' ' | Where-Object { $_ -like "$filter*" } } @@ -40,9 +39,9 @@ $script:someCommands = @('add','am','annotate','archive','bisect','blame','branc 'notes','prune','pull','push','rebase','reflog','remote','rerere','reset','revert','rm', 'shortlog','show','stash','status','submodule','svn','tag','whatchanged', 'worktree') try { - if ($null -ne (git help -a 2>&1 | Select-String flow)) { - $script:someCommands += 'flow' - } + if ($null -ne (git help -a 2>&1 | Select-String flow)) { + $script:someCommands += 'flow' + } } catch { Write-Debug "Search for 'flow' in 'git help' output failed with error: $_" @@ -52,7 +51,8 @@ function script:gitCommands($filter, $includeAliases) { $cmdList = @() if (-not $global:GitTabSettings.AllCommands) { $cmdList += $someCommands -like "$filter*" - } else { + } + else { $cmdList += git help --all | Where-Object { $_ -match '^ \S.*' } | ForEach-Object { $_.Split(' ', [StringSplitOptions]::RemoveEmptyEntries) } | @@ -62,12 +62,12 @@ function script:gitCommands($filter, $includeAliases) { if ($includeAliases) { $cmdList += gitAliases $filter } + $cmdList | Sort-Object } function script:gitRemotes($filter) { - git remote | - Where-Object { $_ -like "$filter*" } + git remote | Where-Object { $_ -like "$filter*" } } function script:gitBranches($filter, $includeHEAD = $false, $prefix = '') { @@ -180,12 +180,12 @@ function script:expandGitAlias($cmd, $rest) { } function GitTabExpansion($lastBlock) { - Invoke-Utf8ConsoleCommand { - GitTabExpansionInternal $lastBlock - } + $res = Invoke-Utf8ConsoleCommand { GitTabExpansionInternal $lastBlock } + $res } function GitTabExpansionInternal($lastBlock) { + $gitParams = '(?\s+-(?:[aA-zZ0-9]+|-[aA-zZ0-9][aA-zZ0-9-]*)(?:=\S+)?)*' if ($lastBlock -match "^$(Get-AliasPattern git) (?\S+)(? .*)$") { $lastBlock = expandGitAlias $Matches['cmd'] $Matches['args'] @@ -209,7 +209,6 @@ function GitTabExpansionInternal($lastBlock) { gitCmdOperations $subcommands $matches['cmd'] $matches['op'] } - # Handles git flow "^flow (?$($gitflowsubcommands.Keys -join '|'))\s+(?\S*)$" { gitCmdOperations $gitflowsubcommands $matches['cmd'] $matches['op'] @@ -258,14 +257,14 @@ function GitTabExpansionInternal($lastBlock) { # Handles git push remote : # Handles git push remote +: - "^push.* (?\S+) (?\+?)(?[^\s\:]*\:)(?\S*)$" { + "^push.* ${gitParams}(?\S+) (?\+?)(?[^\s\:]*\:)(?\S*)$" { gitRemoteBranches $matches['remote'] $matches['ref'] $matches['branch'] -prefix $matches['force'] } # Handles git push remote # Handles git push remote + # Handles git pull remote - "^(?:push|pull).* (?:\S+) (?\+?)(?[^\s\:]*)$" { + "^(?:push|pull).* ${gitParams}(?[^\s-]\S*) (?\+?)(?[^\s\:]*)$" { gitBranches $matches['ref'] -prefix $matches['force'] gitTags $matches['ref'] -prefix $matches['force'] } @@ -273,7 +272,7 @@ function GitTabExpansionInternal($lastBlock) { # Handles git pull # Handles git push # Handles git fetch - "^(?:push|pull|fetch).* (?\S*)$" { + "^(?:push|pull|fetch).* ${gitParams}(?\S*)$" { gitRemotes $matches['remote'] } @@ -360,6 +359,10 @@ function TabExpansion($line, $lastWord) { "^$(Get-AliasPattern gitk) (.*)" { GitTabExpansion $lastBlock } # Fall back on existing tab expansion - default { if (Test-Path Function:\TabExpansionBackup) { TabExpansionBackup $line $lastWord } } + default { + if (Test-Path Function:\TabExpansionBackup) { + TabExpansionBackup $line $lastWord + } + } } } diff --git a/test/TabExpansion.Tests.ps1 b/test/TabExpansion.Tests.ps1 new file mode 100644 index 000000000..ebca5eec7 --- /dev/null +++ b/test/TabExpansion.Tests.ps1 @@ -0,0 +1,22 @@ +. $PSScriptRoot\Shared.ps1 + +Describe 'TabExpansion Tests' { + Context 'Git Push TabExpansion Tests' { + It 'Tab completes remote' { + $result = & $module GitTabExpansionInternal 'git push or' + $result | Should BeExactly 'origin' + } + It 'Tab completes remote and branch' { + $result = & $module GitTabExpansionInternal 'git push origin ma' + $result | Should BeExactly 'master' + } + It 'Tab completes remote with preceding parameters' { + $result = & $module GitTabExpansionInternal 'git push --follow-tags -u or' + $result | Should BeExactly 'origin' + } + It 'Tab completes remote and branch with preceding parameters' { + $result = & $module GitTabExpansionInternal 'git push --follow-tags -u origin ma' + $result | Should BeExactly 'master' + } + } +} diff --git a/test/testDebugHarness.ps1 b/test/testDebugHarness.ps1 index 346fb6b0e..43e933d25 100644 --- a/test/testDebugHarness.ps1 +++ b/test/testDebugHarness.ps1 @@ -1,2 +1,2 @@ -Invoke-Pester $PSScriptRoot\Utils.Tests.ps1 +Invoke-Pester $PSScriptRoot