Skip to content

Commit

Permalink
Merge pull request dahlbyk#868 from dmringo/patch-1
Browse files Browse the repository at this point in the history
Fix branch regex to handle symbolic refs
  • Loading branch information
dahlbyk authored Mar 27, 2022
2 parents 151ce6c + 6dc6d65 commit ad8278e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function script:gitBranches($filter, $includeHEAD = $false, $prefix = '') {
$filter = $matches['to']
}

$branches = @(git branch --no-color | ForEach-Object { if (($_ -notmatch "^\* \(HEAD detached .+\)$") -and ($_ -match "^[\*\+]?\s*(?<ref>.*)")) { $matches['ref'] } }) +
$branches = @(git branch --no-color | ForEach-Object { if (($_ -notmatch "^\* \(HEAD detached .+\)$") -and ($_ -match "^[\*\+]?\s*(?<ref>\S+)(?: -> .+)?")) { $matches['ref'] } }) +
@(git branch --no-color -r | ForEach-Object { if ($_ -match "^ (?<ref>\S+)(?: -> .+)?") { $matches['ref'] } }) +
@(if ($includeHEAD) { 'HEAD','FETCH_HEAD','ORIG_HEAD','MERGE_HEAD' })

Expand Down
16 changes: 16 additions & 0 deletions test/TabExpansion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,22 @@ Describe 'TabExpansion Tests' {
&$gitbin branch -D $branchName
}
}

It 'Tab completes branch names that are symbolic refs' {
$branchName = 'symbolic-ref--for-Pester-tests'
if (&$gitbin branch --list -q $branchName) {
&$gitbin branch -D $branchName
}

&$gitbin symbolic-ref refs/heads/$branchName refs/heads/master
try {
$result = & $module GitTabExpansionInternal 'git checkout symbolic-ref--for-Pester-test'
$result | Should -BeExactly $branchName
}
finally {
&$gitbin branch -D $branchName
}
}
}

Context 'Restore Source Branch TabExpansion Tests' {
Expand Down

0 comments on commit ad8278e

Please sign in to comment.