]> git.ipfire.org Git - thirdparty/git.git/commit - t/t9902-completion.sh
completion: fix completion after 'git --option <TAB>'
authorSZEDER Gábor <szeder@ira.uka.de>
Sun, 15 Apr 2012 19:44:20 +0000 (22:44 +0300)
committerJunio C Hamano <gitster@pobox.com>
Sun, 22 Apr 2012 05:39:07 +0000 (22:39 -0700)
commit911d5da6f20e28cfe16ea539a4f1b86293a7280e
treebafef0a2d3d34f5eebd82bc7c6f5ebadf585fdaf
parent3ffcd08688a0e5f5de808c1077d10552d1f84e70
completion: fix completion after 'git --option <TAB>'

The bash completion doesn't work when certain options to git itself are
specified, e.g. 'git --no-pager <TAB>' 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 <szeder@ira.uka.de>
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash
t/t9902-completion.sh