From 8557a319861d21c0a081ad619ef2dda75d54fc38 Mon Sep 17 00:00:00 2001 From: Dan Turner Date: Mon, 12 Jan 2015 14:24:40 +1100 Subject: [PATCH 1/2] Adds support for shorthand force-push syntax Git supports a short-hand syntax for force-pushing a branch to a remote by including the "+" modifier before the branch name. However when doing so, Posh-git was no longer able to auto-complete the branch name as it did not understand this syntax. This PR adds that support. Closes #173 --- GitTabExpansion.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/GitTabExpansion.ps1 b/GitTabExpansion.ps1 index 224c94da8..81ff02054 100644 --- a/GitTabExpansion.ps1 +++ b/GitTabExpansion.ps1 @@ -223,6 +223,11 @@ function GitTabExpansion($lastBlock) { "^push.* (?\S+) (?[^\s\:]*\:)(?\S*)$" { gitRemoteBranches $matches['remote'] $matches['ref'] $matches['branch'] } + + # Handles git push remote + (force push) + "^push.* (?\S+) (?\+)(?\S*)$" { + gitRemoteBranches $matches['remote'] $matches['ref'] $matches['branch'] + } # Handles git push remote # Handles git pull remote From 6a6f34fc4363975a3d76d18d71b5ca2146ab6d32 Mon Sep 17 00:00:00 2001 From: Keith Dahlby Date: Sat, 31 Dec 2016 00:13:50 -0600 Subject: [PATCH 2/2] Make `git push +` more robust --- GitTabExpansion.ps1 | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/GitTabExpansion.ps1 b/GitTabExpansion.ps1 index ac7f6ca87..45ceee895 100644 --- a/GitTabExpansion.ps1 +++ b/GitTabExpansion.ps1 @@ -65,10 +65,9 @@ function script:gitRemotes($filter) { Where-Object { $_ -like "$filter*" } } -function script:gitBranches($filter, $includeHEAD = $false) { - $prefix = $null +function script:gitBranches($filter, $includeHEAD = $false, $prefix = '') { if ($filter -match "^(?\S*\.{2,3})(?.*)") { - $prefix = $matches['from'] + $prefix += $matches['from'] $filter = $matches['to'] } $branches = @(git branch --no-color | ForEach-Object { if($_ -match "^\*?\s*(?.*)") { $matches['ref'] } }) + @@ -79,9 +78,10 @@ function script:gitBranches($filter, $includeHEAD = $false) { ForEach-Object { $prefix + $_ } } -function script:gitTags($filter) { +function script:gitTags($filter, $prefix = '') { git tag | - Where-Object { $_ -like "$filter*" } + Where-Object { $_ -like "$filter*" } | + ForEach-Object { $prefix + $_ } } function script:gitFeatures($filter, $command){ @@ -92,10 +92,10 @@ function script:gitFeatures($filter, $command){ ForEach-Object { $prefix + $_ } } -function script:gitRemoteBranches($remote, $ref, $filter) { +function script:gitRemoteBranches($remote, $ref, $filter, $prefix = '') { git branch --no-color -r | Where-Object { $_ -like " $remote/$filter*" } | - ForEach-Object { $ref + ($_ -replace " $remote/","") } + ForEach-Object { $prefix + $ref + ($_ -replace " $remote/","") } } function script:gitStashes($filter) { @@ -237,20 +237,17 @@ function GitTabExpansion($lastBlock) { } # Handles git push remote : - "^push.* (?\S+) (?[^\s\:]*\:)(?\S*)$" { - gitRemoteBranches $matches['remote'] $matches['ref'] $matches['branch'] - } - - # Handles git push remote + (force push) - "^push.* (?\S+) (?\+)(?\S*)$" { - gitRemoteBranches $matches['remote'] $matches['ref'] $matches['branch'] + # Handles git push remote +: + "^push.* (?\S+) (?\+?)(?[^\s\:]*\:)(?\S*)$" { + gitRemoteBranches $matches['remote'] $matches['ref'] $matches['branch'] -prefix $matches['force'] } # Handles git push remote + # Handles git push remote + # Handles git pull remote - "^(?:push|pull).* (?:\S+) (?[^\s\:]*)$" { - gitBranches $matches['ref'] - gitTags $matches['ref'] + "^(?:push|pull).* (?:\S+) (?\+?)(?[^\s\:]*)$" { + gitBranches $matches['ref'] -prefix $matches['force'] + gitTags $matches['ref'] -prefix $matches['force'] } # Handles git pull