Skip to content

Commit

Permalink
Merge pull request #352 from dahlbyk/checkout-remote-branch
Browse files Browse the repository at this point in the history
Complete remote unique branches for 'git checkout'
  • Loading branch information
dahlbyk committed Jan 4, 2017
2 parents f992413 + ec76ff9 commit a314b05
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion GitTabExpansion.ps1
Expand Up @@ -82,6 +82,15 @@ function script:gitBranches($filter, $includeHEAD = $false, $prefix = '') {
ForEach-Object { $prefix + $_ }
}

function script:gitRemoteUniqueBranches($filter) {
git branch --no-color -r |
ForEach-Object { if($_ -match "^ (?<remote>[^/]+)/(?<branch>\S+)(?! -> .+)?$") { $matches['branch'] } } |
Group-Object -NoElement |
Where-Object { $_.Count -eq 1 } |
Select-Object -ExpandProperty Name |
Where-Object { $_ -like "$filter*" }
}

function script:gitTags($filter, $prefix = '') {
git tag |
Where-Object { $_ -like "$filter*" } |
Expand Down Expand Up @@ -297,8 +306,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 a314b05

Please sign in to comment.