{"thread":{"id":"28292","subject":"[PATCH] completion: fix completion after 'git --option <TAB>'","startedAt":"2011-09-03T10:32:52Z","lastAt":"2011-09-03T10:32:52Z","messageCount":1,"participants":["SZEDER Gábor"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"174783","messageId":"1315045972-29983-1-git-send-email-szeder@ira.uka.de","threadId":"28292","inReplyTo":null,"subject":"[PATCH] completion: fix completion after 'git --option <TAB>'","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2011-09-03T10:32:52Z","receivedAt":"2011-09-03T10:32:52Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Git's bash completion currently doesn't work when certain git options\nare specified, e.g. 'git --no-pager <TAB>' errors out with \"error:\ninvalid key: alias.--no-pager\".\n\nThe main _git() completion function finds out the git command name by\nlooping through all the words on the command line and searching for\nthe first word that is not a known option for the git command.\nUnfortunately the list of known git options was not updated in a long\ntime, and newer options are not skipped but mistaken for a git\ncommand.  Such a misrecognized \"command\" is then passed to\n__git_aliased_command(), which in turn passes it to a 'git config'\nquery, hence the error.\n\nCurrently the following options are misrecognized for a git command:\n\n  -c --no-pager --exec-path --html-path --man-path --info-path\n  --no-replace-objects --work-tree= --namespace=\n\nTo fix this we could just update the list of options to be skipped,\nbut the same issue will likely arise, if the git command learns a new\noption in the future.  Therefore, to make it more future proof against\nnew options, this patch changes that loop to skip all option-looking\nwords, i.e. words starting with a dash.\n\nWe also have to handle the '-c' option specially, because it takes a\nconfigutation parameter in a separate word, which must be skipped,\ntoo.\n\nSigned-off-by: SZEDER Gábor <szeder@ira.uka.de>\n---\n contrib/completion/git-completion.bash |    3 ++-\n 1 files changed, 2 insertions(+), 1 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 8648a36..8b0c695 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2622,8 +2622,9 @@ _git ()\n \t\tcase \"$i\" in\n \t\t--git-dir=*) __git_dir=\"${i#--git-dir=}\" ;;\n \t\t--bare)      __git_dir=\".\" ;;\n-\t\t--version|-p|--paginate) ;;\n \t\t--help) command=\"help\"; break ;;\n+\t\t-c) c=$((++c)) ;;\n+\t\t-*) ;;\n \t\t*) command=\"$i\"; break ;;\n \t\tesac\n \t\tc=$((++c))\n-- \n1.7.6.596.gedbca\n"}]}