summaryrefslogtreecommitdiff
path: root/contrib/completion
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-11-25 23:24:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-11-25 23:24:51 (GMT)
commitfd6445a0b8346d0dea6482af682f2116229f6436 (patch)
tree4181e14dc8acb7dc859b53e2eaa88d30ec313ca7 /contrib/completion
parentb291b0a628020eedb10b6236d87fe25d295cea81 (diff)
parente4c75edb52acab8c90520ceedab4326b972cc0af (diff)
downloadgit-fd6445a0b8346d0dea6482af682f2116229f6436.zip
git-fd6445a0b8346d0dea6482af682f2116229f6436.tar.gz
git-fd6445a0b8346d0dea6482af682f2116229f6436.tar.bz2
Merge branch 'fc/bash-completion-alias-of-alias'
The command line completion script (in contrib/) learned to expand commands that are alias of alias. * fc/bash-completion-alias-of-alias: completion: bash: improve alias loop detection completion: bash: check for alias loop completion: bash: support recursive aliases
Diffstat (limited to 'contrib/completion')
-rw-r--r--contrib/completion/git-completion.bash54
1 files changed, 36 insertions, 18 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 7c81e4b..1ed0362 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1120,26 +1120,44 @@ __git_pretty_aliases ()
# __git_aliased_command requires 1 argument
__git_aliased_command ()
{
- local word cmdline=$(__git config --get "alias.$1")
- for word in $cmdline; do
- case "$word" in
- \!gitk|gitk)
- echo "gitk"
- return
- ;;
- \!*) : shell command alias ;;
- -*) : option ;;
- *=*) : setting env ;;
- git) : git itself ;;
- \(\)) : skip parens of shell function definition ;;
- {) : skip start of shell helper function ;;
- :) : skip null command ;;
- \'*) : skip opening quote after sh -c ;;
- *)
- echo "$word"
+ local cur=$1 last list word cmdline
+
+ while [[ -n "$cur" ]]; do
+ if [[ "$list" == *" $cur "* ]]; then
+ # loop detected
return
- esac
+ fi
+
+ cmdline=$(__git config --get "alias.$cur")
+ list=" $cur $list"
+ last=$cur
+ cur=
+
+ for word in $cmdline; do
+ case "$word" in
+ \!gitk|gitk)
+ cur="gitk"
+ break
+ ;;
+ \!*) : shell command alias ;;
+ -*) : option ;;
+ *=*) : setting env ;;
+ git) : git itself ;;
+ \(\)) : skip parens of shell function definition ;;
+ {) : skip start of shell helper function ;;
+ :) : skip null command ;;
+ \'*) : skip opening quote after sh -c ;;
+ *)
+ cur="$word"
+ break
+ esac
+ done
done
+
+ cur=$last
+ if [[ "$cur" != "$1" ]]; then
+ echo "$cur"
+ fi
}
# Check whether one of the given words is present on the command line,