From ed8fcb88c9ae47b0710ecfcf58bccd4283910ce7 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Tue, 8 Oct 2019 18:29:59 -0600 Subject: [PATCH 1/2] Fix bug w/multiple completions of name parameter on remove-gitbranch This is better because it uses the more direct mechanism for parameter argument completion for cmdlets. Fix help markdown warning in this cmdlet. --- src/GitTabExpansion.ps1 | 13 ++++++------- src/GitUtils.ps1 | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/GitTabExpansion.ps1 b/src/GitTabExpansion.ps1 index 0cd1dfd28..4180935f8 100644 --- a/src/GitTabExpansion.ps1 +++ b/src/GitTabExpansion.ps1 @@ -278,12 +278,6 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) { return gitBranches $matches['ref'] $true } - # Handles Remove-GitBranch - if (($lastBlock -match "^Remove-GitBranch\s+(?!-)(?\S*)") -or - ($lastBlock -match "^Remove-GitBranch.* -Name\s+(?\S*)")) { - return gitBranches $matches['ref'] $true - } - switch -regex ($lastBlock -replace "^$(Get-AliasPattern git) ","") { # Handles git @@ -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 { @@ -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 +} diff --git a/src/GitUtils.ps1 b/src/GitUtils.ps1 index da013594e..41a34504c 100644 --- a/src/GitUtils.ps1 +++ b/src/GitUtils.ps1 @@ -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: From 81b3f1ebaa0207c710509ffa379c81ab1b9b9c98 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Tue, 8 Oct 2019 18:57:05 -0600 Subject: [PATCH 2/2] Remove tab exp tests for Remove-GitBranch until we find another approach --- test/TabExpansion.Tests.ps1 | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/TabExpansion.Tests.ps1 b/test/TabExpansion.Tests.ps1 index 32d387931..822f45801 100644 --- a/test/TabExpansion.Tests.ps1 +++ b/test/TabExpansion.Tests.ps1 @@ -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', '')]