aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/completion
diff options
context:
space:
mode:
authorFelipe Contreras <felipe.contreras@gmail.com>2020-11-12 16:34:52 -0600
committerJunio C Hamano <gitster@pobox.com>2020-11-17 10:57:46 -0800
commite4c75edb52acab8c90520ceedab4326b972cc0af (patch)
tree722aa52162666cb8eca584c22f944ee9fc199f13 /contrib/completion
parentc2822a842dc993722a9d6f8226189312b95d8801 (diff)
downloadgit-e4c75edb52acab8c90520ceedab4326b972cc0af.tar.gz
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 <szeder.dev@gmail.com> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/completion')
-rw-r--r--contrib/completion/git-completion.bash9
1 files changed, 5 insertions, 4 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 8fcf464bc3..1ed03623cd 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1120,16 +1120,17 @@ __git_pretty_aliases ()
# __git_aliased_command requires 1 argument
__git_aliased_command ()
{
- local cur=$1 list word cmdline
+ local cur=$1 last list word cmdline
while [[ -n "$cur" ]]; do
- if [[ "$list" == *"$cur "* ]]; then
+ if [[ "$list" == *" $cur "* ]]; then
# loop detected
return
fi
cmdline=$(__git config --get "alias.$cur")
- list="$cur $list"
+ list=" $cur $list"
+ last=$cur
cur=
for word in $cmdline; do
@@ -1153,7 +1154,7 @@ __git_aliased_command ()
done
done
- cur="${list%% *}"
+ cur=$last
if [[ "$cur" != "$1" ]]; then
echo "$cur"
fi