Skip to content

Commit c2822a8

Browse files
felipecgitster
authored andcommitted
completion: bash: check for alias loop
We don't want to be stuck in an endless cycle. Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9414938 commit c2822a8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

contrib/completion/git-completion.bash

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

11251125
while [[ -n "$cur" ]]; do
1126+
if [[ "$list" == *"$cur "* ]]; then
1127+
# loop detected
1128+
return
1129+
fi
1130+
11261131
cmdline=$(__git config --get "alias.$cur")
1127-
last=$cur
1132+
list="$cur $list"
11281133
cur=
11291134

11301135
for word in $cmdline; do
@@ -1148,7 +1153,7 @@ __git_aliased_command ()
11481153
done
11491154
done
11501155

1151-
cur=$last
1156+
cur="${list%% *}"
11521157
if [[ "$cur" != "$1" ]]; then
11531158
echo "$cur"
11541159
fi

0 commit comments

Comments
 (0)