Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug w/multiple completions of name parameter on remove-gitbranch #705

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,6 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) {
return gitBranches $matches['ref'] $true
}

# Handles Remove-GitBranch
if (($lastBlock -match "^Remove-GitBranch\s+(?!-)(?<ref>\S*)") -or
($lastBlock -match "^Remove-GitBranch.* -Name\s+(?<ref>\S*)")) {
return gitBranches $matches['ref'] $true
}

switch -regex ($lastBlock -replace "^$(Get-AliasPattern git) ","") {

# Handles git <cmd> <op>
Expand Down Expand Up @@ -474,7 +468,6 @@ function TabExpansion($line, $lastWord) {
"^$(Get-AliasPattern git) (.*)" { Expand-GitCommand $lastBlock }
"^$(Get-AliasPattern tgit) (.*)" { Expand-GitCommand $lastBlock }
"^$(Get-AliasPattern gitk) (.*)" { Expand-GitCommand $lastBlock }
"^$(Get-AliasPattern Remove-GitBranch) (.*)" { Expand-GitCommand $lastBlock }

# Fall back on existing tab expansion
default {
Expand All @@ -484,3 +477,9 @@ function TabExpansion($line, $lastWord) {
}
}
}

# Handles Remove-GitBranch -Name parameter auto-completion using the built-in mechanism for cmdlet parameters
Register-ArgumentCompleter -CommandName Remove-GitBranch -ParameterName Name -ScriptBlock {
param($Command, $Parameter, $WordToComplete, $CommandAst, $FakeBoundParams)
gitBranches $WordToComplete $true
}
2 changes: 1 addition & 1 deletion src/GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ function Get-AliasPattern($cmd) {

Where-Object { $_ -match $Pattern }

## Recovering Deleted Branches
Recovering Deleted Branches

If you wind up deleting a branch you didn't intend to, you can easily recover it with the info provided by Git during the delete. For instance, let's say you realized you didn't want to delete the branch 'feature/exp1'. In the output of this command, you should see a deletion entry for this branch that looks like:

Expand Down
11 changes: 0 additions & 11 deletions test/TabExpansion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,6 @@ Describe 'TabExpansion Tests' {
}
}

Context 'Remove-GitBranch TabExpansion Tests' {
It 'Tab completes branches by positional parameter' {
$result = & $module GitTabExpansionInternal 'Remove-GitBranch mas'
$result | Should BeExactly 'master'
}
It 'Tab completes branches by named parameter' {
$result = & $module GitTabExpansionInternal 'Remove-GitBranch -IncludeUnmerged -WhatIf -Name mas'
$result | Should BeExactly 'master'
}
}

Context 'Vsts' {
BeforeEach {
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
Expand Down