From: SZEDER Gábor Date: Sun, 15 Apr 2012 19:44:20 +0000 (+0300) Subject: completion: fix completion after 'git --option ' X-Git-Tag: v1.7.11-rc0~104^2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=911d5da6f20e28cfe16ea539a4f1b86293a7280e;p=git.git completion: fix completion after 'git --option ' The bash completion doesn't work when certain options to git itself are specified, e.g. 'git --no-pager ' errors out with error: invalid key: alias.--no-pager The main _git() completion function finds out the git command name by looping through all the words on the command line and searching for the first word that is not a known option for the git command. Unfortunately the list of known git options was not updated in a long time, and newer options are not skipped but mistaken for a git command. Such a misrecognized "command" is then passed to __git_aliased_command(), which in turn passes it to a 'git config' query, hence the error. Currently the following options are misrecognized for a git command: -c --no-pager --exec-path --html-path --man-path --info-path --no-replace-objects --work-tree= --namespace= To fix this we could just update the list of options to be skipped, but the same issue will likely arise, if the git command learns a new option in the future. Therefore, to make it more future proof against new options, this patch changes that loop to skip all option-looking words, i.e. words starting with a dash. We also have to handle the '-c' option specially, because it takes a configutation parameter in a separate word, which must be skipped, too. [fc: added tests] Signed-off-by: SZEDER Gábor Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 6486a0927..9f56ec7a6 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2623,8 +2623,9 @@ _git () case "$i" in --git-dir=*) __git_dir="${i#--git-dir=}" ;; --bare) __git_dir="." ;; - --version|-p|--paginate) ;; --help) command="help"; break ;; + -c) c=$((++c)) ;; + -*) ;; *) command="$i"; break ;; esac ((c++)) diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index eb779d58a..5bda6b6e1 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -223,4 +223,21 @@ test_expect_success 'general options' ' test_completion "git --inf" "--info-path " && test_completion "git --no-r" "--no-replace-objects " ' + +test_expect_success 'general options plus command' ' + test_completion "git --version check" "checkout " && + test_completion "git --paginate check" "checkout " && + test_completion "git --git-dir=foo check" "checkout " && + test_completion "git --bare check" "checkout " && + test_completion "git --help des" "describe " && + test_completion "git --exec-path=foo check" "checkout " && + test_completion "git --html-path check" "checkout " && + test_completion "git --no-pager check" "checkout " && + test_completion "git --work-tree=foo check" "checkout " && + test_completion "git --namespace=foo check" "checkout " && + test_completion "git --paginate check" "checkout " && + test_completion "git --info-path check" "checkout " && + test_completion "git --no-replace-objects check" "checkout " +' + test_done