From fde87db5f4a2c1d0a7e38bf29846a9ff72a86c7b Mon Sep 17 00:00:00 2001 From: "Mark A. Hillebrand" Date: Sun, 31 Jan 2016 13:25:25 +0100 Subject: [PATCH] GitTabExpansion.ps1: complete remote unique branches for 'git checkout' See 'git help checkout', specifying a branch that doesn't exist locally but exists in exactly one remote will set up a tracking branch. --- GitTabExpansion.ps1 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/GitTabExpansion.ps1 b/GitTabExpansion.ps1 index d21c77b64..3e983b638 100644 --- a/GitTabExpansion.ps1 +++ b/GitTabExpansion.ps1 @@ -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 '/(?.+)') { $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*" } @@ -283,8 +293,15 @@ function GitTabExpansion($lastBlock) { gitMergeFiles $matches['files'] } + # Handles git checkout + "^(?:checkout).* (?\S*)$" { + gitBranches $matches['ref'] $true + gitRemoteUniqueBranches $matches['ref'] + gitTags $matches['ref'] + } + # Handles git - "^(?:checkout|cherry|cherry-pick|diff|difftool|log|merge|rebase|reflog\s+show|reset|revert|show).* (?\S*)$" { + "^(?:cherry|cherry-pick|diff|difftool|log|merge|rebase|reflog\s+show|reset|revert|show).* (?\S*)$" { gitBranches $matches['ref'] $true gitTags $matches['ref'] }