@@ -29,20 +29,18 @@ $gitflowsubcommands = @{
29
29
}
30
30
31
31
function script :gitCmdOperations ($commands , $command , $filter ) {
32
- $commands .$command -split ' ' |
33
- Where-Object { $_ -like " $filter *" }
32
+ $commands .$command -split ' ' | Where-Object { $_ -like " $filter *" }
34
33
}
35
34
36
-
37
35
$script :someCommands = @ (' add' , ' am' , ' annotate' , ' archive' , ' bisect' , ' blame' , ' branch' , ' bundle' , ' checkout' , ' cherry' ,
38
36
' cherry-pick' , ' citool' , ' clean' , ' clone' , ' commit' , ' config' , ' describe' , ' diff' , ' difftool' , ' fetch' ,
39
37
' format-patch' , ' gc' , ' grep' , ' gui' , ' help' , ' init' , ' instaweb' , ' log' , ' merge' , ' mergetool' , ' mv' ,
40
38
' notes' , ' prune' , ' pull' , ' push' , ' rebase' , ' reflog' , ' remote' , ' rerere' , ' reset' , ' revert' , ' rm' ,
41
39
' shortlog' , ' show' , ' stash' , ' status' , ' submodule' , ' svn' , ' tag' , ' whatchanged' , ' worktree' )
42
40
try {
43
- if ($null -ne (git help - a 2>&1 | Select-String flow)) {
44
- $script :someCommands += ' flow'
45
- }
41
+ if ($null -ne (git help - a 2>&1 | Select-String flow)) {
42
+ $script :someCommands += ' flow'
43
+ }
46
44
}
47
45
catch {
48
46
Write-Debug " Search for 'flow' in 'git help' output failed with error: $_ "
@@ -52,7 +50,8 @@ function script:gitCommands($filter, $includeAliases) {
52
50
$cmdList = @ ()
53
51
if (-not $global :GitTabSettings.AllCommands ) {
54
52
$cmdList += $someCommands -like " $filter *"
55
- } else {
53
+ }
54
+ else {
56
55
$cmdList += git help -- all |
57
56
Where-Object { $_ -match ' ^ \S.*' } |
58
57
ForEach-Object { $_.Split (' ' , [StringSplitOptions ]::RemoveEmptyEntries) } |
@@ -62,30 +61,32 @@ function script:gitCommands($filter, $includeAliases) {
62
61
if ($includeAliases ) {
63
62
$cmdList += gitAliases $filter
64
63
}
64
+
65
65
$cmdList | Sort-Object
66
66
}
67
67
68
68
function script :gitRemotes ($filter ) {
69
- git remote |
70
- Where-Object { $_ -like " $filter *" }
69
+ git remote | Where-Object { $_ -like " $filter *" }
71
70
}
72
71
73
72
function script :gitBranches ($filter , $includeHEAD = $false , $prefix = ' ' ) {
74
73
if ($filter -match " ^(?<from>\S*\.{2,3})(?<to>.*)" ) {
75
74
$prefix += $matches [' from' ]
76
75
$filter = $matches [' to' ]
77
76
}
78
- $branches = @ (git branch -- no- color | ForEach-Object { if (($_ -notmatch " ^\* \(HEAD detached .+\)$" ) -and ($_ -match " ^\*?\s*(?<ref>.*)" )) { $matches [' ref' ] } }) +
79
- @ (git branch -- no- color - r | ForEach-Object { if ($_ -match " ^ (?<ref>\S+)(?: -> .+)?" ) { $matches [' ref' ] } }) +
77
+
78
+ $branches = @ (git branch -- no- color | ForEach-Object { if (($_ -notmatch " ^\* \(HEAD detached .+\)$" ) -and ($_ -match " ^\*?\s*(?<ref>.*)" )) { $matches [' ref' ] } }) +
79
+ @ (git branch -- no- color - r | ForEach-Object { if ($_ -match " ^ (?<ref>\S+)(?: -> .+)?" ) { $matches [' ref' ] } }) +
80
80
@ (if ($includeHEAD ) { ' HEAD' , ' FETCH_HEAD' , ' ORIG_HEAD' , ' MERGE_HEAD' })
81
+
81
82
$branches |
82
83
Where-Object { $_ -ne ' (no branch)' -and $_ -like " $filter *" } |
83
84
ForEach-Object { $prefix + $_ }
84
85
}
85
86
86
87
function script :gitRemoteUniqueBranches ($filter ) {
87
88
git branch -- no- color - r |
88
- ForEach-Object { if ($_ -match " ^ (?<remote>[^/]+)/(?<branch>\S+)(?! -> .+)?$" ) { $matches [' branch' ] } } |
89
+ ForEach-Object { if ($_ -match " ^ (?<remote>[^/]+)/(?<branch>\S+)(?! -> .+)?$" ) { $matches [' branch' ] } } |
89
90
Group-Object - NoElement |
90
91
Where-Object { $_.Count -eq 1 } |
91
92
Select-Object - ExpandProperty Name |
@@ -100,7 +101,7 @@ function script:gitTags($filter, $prefix = '') {
100
101
101
102
function script :gitFeatures ($filter , $command ){
102
103
$featurePrefix = git config -- local -- get " gitflow.prefix.$command "
103
- $branches = @ (git branch -- no- color | ForEach-Object { if ($_ -match " ^\*?\s*$featurePrefix (?<ref>.*)" ) { $matches [' ref' ] } })
104
+ $branches = @ (git branch -- no- color | ForEach-Object { if ($_ -match " ^\*?\s*$featurePrefix (?<ref>.*)" ) { $matches [' ref' ] } })
104
105
$branches |
105
106
Where-Object { $_ -ne ' (no branch)' -and $_ -like " $filter *" } |
106
107
ForEach-Object { $prefix + $_ }
@@ -127,7 +128,7 @@ function script:gitTfsShelvesets($filter) {
127
128
function script :gitFiles ($filter , $files ) {
128
129
$files | Sort-Object |
129
130
Where-Object { $_ -like " $filter *" } |
130
- ForEach-Object { if ($_ -like ' * *' ) { " '$_ '" } else { $_ } }
131
+ ForEach-Object { if ($_ -like ' * *' ) { " '$_ '" } else { $_ } }
131
132
}
132
133
133
134
function script :gitIndex ($filter ) {
@@ -161,9 +162,9 @@ function script:gitDeleted($filter) {
161
162
162
163
function script :gitAliases ($filter ) {
163
164
git config -- get-regexp ^alias\. | ForEach-Object {
164
- if ($_ -match " ^alias\.(?<alias>\S+) .*" ) {
165
+ if ($_ -match " ^alias\.(?<alias>\S+) .*" ) {
165
166
$alias = $Matches [' alias' ]
166
- if ($alias -like " $filter *" ) {
167
+ if ($alias -like " $filter *" ) {
167
168
$alias
168
169
}
169
170
}
@@ -180,12 +181,12 @@ function script:expandGitAlias($cmd, $rest) {
180
181
}
181
182
182
183
function GitTabExpansion ($lastBlock ) {
183
- Invoke-Utf8ConsoleCommand {
184
- GitTabExpansionInternal $lastBlock
185
- }
184
+ $res = Invoke-Utf8ConsoleCommand { GitTabExpansionInternal $lastBlock }
185
+ $res
186
186
}
187
187
188
188
function GitTabExpansionInternal ($lastBlock ) {
189
+ $gitParams = ' (?<params>\s+-(?:[aA-zZ0-9]+|-[aA-zZ0-9][aA-zZ0-9-]*)(?:=\S+)?)*'
189
190
190
191
if ($lastBlock -match " ^$ ( Get-AliasPattern git) (?<cmd>\S+)(?<args> .*)$" ) {
191
192
$lastBlock = expandGitAlias $Matches [' cmd' ] $Matches [' args' ]
@@ -209,7 +210,6 @@ function GitTabExpansionInternal($lastBlock) {
209
210
gitCmdOperations $subcommands $matches [' cmd' ] $matches [' op' ]
210
211
}
211
212
212
-
213
213
# Handles git flow <cmd> <op>
214
214
" ^flow (?<cmd>$ ( $gitflowsubcommands.Keys -join ' |' ) )\s+(?<op>\S*)$" {
215
215
gitCmdOperations $gitflowsubcommands $matches [' cmd' ] $matches [' op' ]
@@ -258,22 +258,22 @@ function GitTabExpansionInternal($lastBlock) {
258
258
259
259
# Handles git push remote <ref>:<branch>
260
260
# Handles git push remote +<ref>:<branch>
261
- " ^push.* (?<remote>\S+) (?<force>\+?)(?<ref>[^\s\:]*\:)(?<branch>\S*)$" {
261
+ " ^push.* ${gitParams} (?<remote>\S+) (?<force>\+?)(?<ref>[^\s\:]*\:)(?<branch>\S*)$" {
262
262
gitRemoteBranches $matches [' remote' ] $matches [' ref' ] $matches [' branch' ] - prefix $matches [' force' ]
263
263
}
264
264
265
265
# Handles git push remote <ref>
266
266
# Handles git push remote +<ref>
267
267
# Handles git pull remote <ref>
268
- " ^(?:push|pull).* (?:\S+ ) (?<force>\+?)(?<ref>[^\s\:]*)$" {
268
+ " ^(?:push|pull).* ${gitParams} (?<remote>[^\s-]\S* ) (?<force>\+?)(?<ref>[^\s\:]*)$" {
269
269
gitBranches $matches [' ref' ] - prefix $matches [' force' ]
270
270
gitTags $matches [' ref' ] - prefix $matches [' force' ]
271
271
}
272
272
273
273
# Handles git pull <remote>
274
274
# Handles git push <remote>
275
275
# Handles git fetch <remote>
276
- " ^(?:push|pull|fetch).* (?<remote>\S*)$" {
276
+ " ^(?:push|pull|fetch).* ${gitParams} (?<remote>\S*)$" {
277
277
gitRemotes $matches [' remote' ]
278
278
}
279
279
@@ -360,6 +360,10 @@ function TabExpansion($line, $lastWord) {
360
360
" ^$ ( Get-AliasPattern gitk) (.*)" { GitTabExpansion $lastBlock }
361
361
362
362
# Fall back on existing tab expansion
363
- default { if (Test-Path Function:\TabExpansionBackup) { TabExpansionBackup $line $lastWord } }
363
+ default {
364
+ if (Test-Path Function:\TabExpansionBackup) {
365
+ TabExpansionBackup $line $lastWord
366
+ }
367
+ }
364
368
}
365
369
}
0 commit comments