Skip to content

Commit

Permalink
Merge pull request #678 from dahlbyk/rkeithhill/add-branch-completion…
Browse files Browse the repository at this point in the history
…-remove-gitbranch

Add branch name completion to Name param of Remove-GitBranch
  • Loading branch information
rkeithhill committed May 12, 2019
2 parents f936d72 + 547f0a9 commit 5a581a7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ 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 @@ -440,7 +446,6 @@ function GitTabExpansionInternal($lastBlock, $GitStatus = $null) {
{
expandShortParams $shortVstsParams $matches['cmd'] $matches['shortparam']
}

}
}

Expand Down Expand Up @@ -469,6 +474,7 @@ 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 Down
4 changes: 2 additions & 2 deletions src/GitUtils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,8 @@ function InDotGitOrBareRepoDir([string][ValidateNotNullOrEmpty()]$GitDir) {
$res
}

function Get-AliasPattern($exe) {
$aliases = @($exe) + @(Get-Alias | Where-Object { $_.Definition -eq $exe } | Select-Object -Exp Name)
function Get-AliasPattern($cmd) {
$aliases = @($cmd) + @(Get-Alias | Where-Object { $_.Definition -eq $cmd } | Select-Object -Exp Name)
"($($aliases -join '|'))"
}

Expand Down
11 changes: 11 additions & 0 deletions test/TabExpansion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,17 @@ 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

0 comments on commit 5a581a7

Please sign in to comment.