Skip to content

Commit e4c75ed

Browse files
felipecgitster
authored andcommitted
completion: bash: improve alias loop detection
It is possible for the name of an alias to end with the name of another alias, in which case the code will incorrectly detect a loop. We can fix that by adding an extra space between words. Suggested-by: SZEDER Gábor <[email protected]> Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c2822a8 commit e4c75ed

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

contrib/completion/git-completion.bash

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,16 +1120,17 @@ __git_pretty_aliases ()
11201120
# __git_aliased_command requires 1 argument
11211121
__git_aliased_command ()
11221122
{
1123-
local cur=$1 list word cmdline
1123+
local cur=$1 last list word cmdline
11241124

11251125
while [[ -n "$cur" ]]; do
1126-
if [[ "$list" == *"$cur "* ]]; then
1126+
if [[ "$list" == *" $cur "* ]]; then
11271127
# loop detected
11281128
return
11291129
fi
11301130

11311131
cmdline=$(__git config --get "alias.$cur")
1132-
list="$cur $list"
1132+
list=" $cur $list"
1133+
last=$cur
11331134
cur=
11341135

11351136
for word in $cmdline; do
@@ -1153,7 +1154,7 @@ __git_aliased_command ()
11531154
done
11541155
done
11551156

1156-
cur="${list%% *}"
1157+
cur=$last
11571158
if [[ "$cur" != "$1" ]]; then
11581159
echo "$cur"
11591160
fi

0 commit comments

Comments
 (0)