Skip to content

Commit

Permalink
GitTabExpansion.ps1: complete remote unique branches for 'git checkout'
Browse files Browse the repository at this point in the history
See 'git help checkout', specifying a branch that doesn't exist locally
but exists in exactly one remote will set up a tracking branch.
  • Loading branch information
mah committed Jan 31, 2016
1 parent 7210894 commit fde87db
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion GitTabExpansion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ function script:gitBranches($filter, $includeHEAD = $false) {
foreach { $prefix + $_ }
}

function script:gitRemoteUniqueBranches($filter) {
git branch --no-color -r |
where { $_ -notlike '* -> ' } |
foreach { if ($_ -match '/(?<Branch>.+)') { $matches['Branch'] } } |
Group-Object -NoElement |
where { $_.Count -eq 1 } |
Select-Object -ExpandProperty Name |
where { $_ -like "$filter*" }
}

function script:gitTags($filter) {
git tag |
where { $_ -like "$filter*" }
Expand Down Expand Up @@ -283,8 +293,15 @@ function GitTabExpansion($lastBlock) {
gitMergeFiles $matches['files']
}

# Handles git checkout <ref>
"^(?:checkout).* (?<ref>\S*)$" {
gitBranches $matches['ref'] $true
gitRemoteUniqueBranches $matches['ref']
gitTags $matches['ref']
}

# Handles git <cmd> <ref>
"^(?:checkout|cherry|cherry-pick|diff|difftool|log|merge|rebase|reflog\s+show|reset|revert|show).* (?<ref>\S*)$" {
"^(?:cherry|cherry-pick|diff|difftool|log|merge|rebase|reflog\s+show|reset|revert|show).* (?<ref>\S*)$" {
gitBranches $matches['ref'] $true
gitTags $matches['ref']
}
Expand Down

0 comments on commit fde87db

Please sign in to comment.