{"thread":{"id":"30251","subject":"[PATCH v4 0/5] completion: trivial cleanups and fixes","startedAt":"2012-04-15T19:44:15Z","lastAt":"2012-04-15T21:45:46Z","messageCount":7,"participants":["Felipe Contreras","Junio C Hamano"],"isPatch":true,"patchVersion":4,"patchTotal":5},"messages":[{"id":"189347","messageId":"1334519060-2348-1-git-send-email-felipe.contreras@gmail.com","threadId":"30251","inReplyTo":null,"subject":"[PATCH v4 0/5] completion: trivial cleanups and fixes","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-04-15T19:44:15Z","receivedAt":"2012-04-15T19:44:15Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Hi,\n\nJust a few simpliciations, improvements, and add some missing options.\n\nThis series depends on the bash completion tests patch.\n\nSince v3:\n\n * Fix potential issues with __gitcomp_1 and simplify even more\n\nSince v2:\n\n * Add 'git --option <TAB>' fix\n * Improve --exec-path patch\n\nFelipe Contreras (3):\n  completion: simplify __gitcomp_1\n  completion: simplify by using $prev\n  completion: add missing general options\n\nJonathan Nieder (1):\n  completion: avoid trailing space for --exec-path\n\nSZEDER Gábor (1):\n  completion: fix completion after 'git --option <TAB>'\n\n contrib/completion/git-completion.bash |   22 ++++++++++--------\n t/t9902-completion.sh                  |   38 ++++++++++++++++++++++++++++++++\n 2 files changed, 51 insertions(+), 9 deletions(-)\n\n-- \n1.7.10.1.g1f19b8.dirty\n"},{"id":"189350","messageId":"1334519060-2348-2-git-send-email-felipe.contreras@gmail.com","threadId":"30251","inReplyTo":"1334519060-2348-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v4 1/5] completion: simplify __gitcomp_1","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-04-15T19:44:16Z","receivedAt":"2012-04-15T19:44:16Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash |   12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 31f714d..db2d3cc 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -304,16 +304,16 @@ __git_ps1 ()\n \tfi\n }\n \n-# __gitcomp_1 requires 2 arguments\n __gitcomp_1 ()\n {\n-\tlocal c IFS=' '$'\\t'$'\\n'\n+\tlocal c IFS=$' \\t\\n'\n \tfor c in $1; do\n-\t\tcase \"$c$2\" in\n-\t\t--*=*) printf %s$'\\n' \"$c$2\" ;;\n-\t\t*.)    printf %s$'\\n' \"$c$2\" ;;\n-\t\t*)     printf %s$'\\n' \"$c$2 \" ;;\n+\t\tc=\"$c$2\"\n+\t\tcase $c in\n+\t\t--*=*|*.) ;;\n+\t\t*) c=\"$c \" ;;\n \t\tesac\n+\t\tprintf '%s\\n' \"$c\"\n \tdone\n }\n \n-- \n1.7.10.1.g1f19b8.dirty\n"},{"id":"189349","messageId":"1334519060-2348-3-git-send-email-felipe.contreras@gmail.com","threadId":"30251","inReplyTo":"1334519060-2348-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v4 2/5] completion: simplify by using $prev","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-04-15T19:44:17Z","receivedAt":"2012-04-15T19:44:17Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"cword-1 is the previous word ($prev).\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash |    4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex db2d3cc..8c91faf 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1658,7 +1658,7 @@ _git_notes ()\n \t\t__gitcomp '--ref'\n \t\t;;\n \t,*)\n-\t\tcase \"${words[cword-1]}\" in\n+\t\tcase \"$prev\" in\n \t\t--ref)\n \t\t\t__gitcomp_nl \"$(__git_refs)\"\n \t\t\t;;\n@@ -1684,7 +1684,7 @@ _git_notes ()\n \tprune,*)\n \t\t;;\n \t*)\n-\t\tcase \"${words[cword-1]}\" in\n+\t\tcase \"$prev\" in\n \t\t-m|-F)\n \t\t\t;;\n \t\t*)\n-- \n1.7.10.1.g1f19b8.dirty\n"},{"id":"189348","messageId":"1334519060-2348-4-git-send-email-felipe.contreras@gmail.com","threadId":"30251","inReplyTo":"1334519060-2348-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v4 3/5] completion: add missing general options","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-04-15T19:44:18Z","receivedAt":"2012-04-15T19:44:18Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"And add relevant tests.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash |    2 ++\n t/t9902-completion.sh                  |   16 ++++++++++++++++\n 2 files changed, 18 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 8c91faf..b837704 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2640,8 +2640,10 @@ _git ()\n \t\t\t--version\n \t\t\t--exec-path\n \t\t\t--html-path\n+\t\t\t--info-path\n \t\t\t--work-tree=\n \t\t\t--namespace=\n+\t\t\t--no-replace-objects\n \t\t\t--help\n \t\t\t\"\n \t\t\t;;\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 7bd37f5..f24c968 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -95,8 +95,10 @@ test_expect_success 'double dash \"git\" itself' '\n \t--version Z\n \t--exec-path Z\n \t--html-path Z\n+\t--info-path Z\n \t--work-tree=\n \t--namespace=\n+\t--no-replace-objects Z\n \t--help Z\n \tEOF\n \ttest_completion \"git --\"\n@@ -117,4 +119,18 @@ test_expect_success 'double dash \"git checkout\"' '\n \ttest_completion \"git checkout --\"\n '\n \n+test_expect_success 'general options' '\n+\ttest_completion \"git --ver\" \"--version \" &&\n+\ttest_completion \"git --hel\" \"--help \" &&\n+\ttest_completion \"git --exe\" \"--exec-path \" &&\n+\ttest_completion \"git --htm\" \"--html-path \" &&\n+\ttest_completion \"git --pag\" \"--paginate \" &&\n+\ttest_completion \"git --no-p\" \"--no-pager \" &&\n+\ttest_completion \"git --git\" \"--git-dir=\" &&\n+\ttest_completion \"git --wor\" \"--work-tree=\" &&\n+\ttest_completion \"git --nam\" \"--namespace=\" &&\n+\ttest_completion \"git --bar\" \"--bare \" &&\n+\ttest_completion \"git --inf\" \"--info-path \" &&\n+\ttest_completion \"git --no-r\" \"--no-replace-objects \"\n+'\n test_done\n-- \n1.7.10.1.g1f19b8.dirty\n"},{"id":"189351","messageId":"1334519060-2348-5-git-send-email-felipe.contreras@gmail.com","threadId":"30251","inReplyTo":"1334519060-2348-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v4 4/5] completion: avoid trailing space for --exec-path","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-04-15T19:44:19Z","receivedAt":"2012-04-15T19:44:19Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"From: Jonathan Nieder <jrnieder@gmail.com>\n\n--exec-path looks to the completion script like an unambiguous\nsuccessful completion, but it is wrong; the user could be trying to\ndo\n\n\tgit --exec-path; # print name of helper directory\n\nor\n\n\tgit --exec-path=/path/to/alternative/helper/dir <subcommand>\n\nso the most helpful thing to do is to leave out the trailing space and\nleave it to the operator to type an equal sign or carriage return\naccording to the situation.\n\nCc: Andreas Schwab <schwab@linux-m68k.org>\nReported-by: Felipe Contreras <felipe.contreras@gmail.com>\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n[added tests]\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash |    1 +\n t/t9902-completion.sh                  |    7 ++++++-\n 2 files changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex b837704..6486a09 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2639,6 +2639,7 @@ _git ()\n \t\t\t--bare\n \t\t\t--version\n \t\t\t--exec-path\n+\t\t\t--exec-path=\n \t\t\t--html-path\n \t\t\t--info-path\n \t\t\t--work-tree=\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex f24c968..dfef809 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -94,6 +94,7 @@ test_expect_success 'double dash \"git\" itself' '\n \t--bare Z\n \t--version Z\n \t--exec-path Z\n+\t--exec-path=\n \t--html-path Z\n \t--info-path Z\n \t--work-tree=\n@@ -122,7 +123,11 @@ test_expect_success 'double dash \"git checkout\"' '\n test_expect_success 'general options' '\n \ttest_completion \"git --ver\" \"--version \" &&\n \ttest_completion \"git --hel\" \"--help \" &&\n-\ttest_completion \"git --exe\" \"--exec-path \" &&\n+\tsed -e \"s/Z$//\" >expected <<-\\EOF &&\n+\t--exec-path Z\n+\t--exec-path=\n+\tEOF\n+\ttest_completion \"git --exe\" &&\n \ttest_completion \"git --htm\" \"--html-path \" &&\n \ttest_completion \"git --pag\" \"--paginate \" &&\n \ttest_completion \"git --no-p\" \"--no-pager \" &&\n-- \n1.7.10.1.g1f19b8.dirty\n"},{"id":"189352","messageId":"1334519060-2348-6-git-send-email-felipe.contreras@gmail.com","threadId":"30251","inReplyTo":"1334519060-2348-1-git-send-email-felipe.contreras@gmail.com","subject":"[PATCH v4 5/5] completion: fix completion after 'git --option <TAB>'","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2012-04-15T19:44:20Z","receivedAt":"2012-04-15T19:44:20Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"From: SZEDER Gábor <szeder@ira.uka.de>\n\nGit'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[added tests]\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n contrib/completion/git-completion.bash |    3 ++-\n t/t9902-completion.sh                  |   17 +++++++++++++++++\n 2 files changed, 19 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 6486a09..9f56ec7 100755\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -2623,8 +2623,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\t((c++))\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex dfef809..ab72378 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -138,4 +138,21 @@ test_expect_success 'general options' '\n \ttest_completion \"git --inf\" \"--info-path \" &&\n \ttest_completion \"git --no-r\" \"--no-replace-objects \"\n '\n+\n+test_expect_success 'general options plus command' '\n+\ttest_completion \"git --version check\" \"checkout \" &&\n+\ttest_completion \"git --paginate check\" \"checkout \" &&\n+\ttest_completion \"git --git-dir=foo check\" \"checkout \" &&\n+\ttest_completion \"git --bare check\" \"checkout \" &&\n+\ttest_completion \"git --help des\" \"describe \" &&\n+\ttest_completion \"git --exec-path=foo check\" \"checkout \" &&\n+\ttest_completion \"git --html-path check\" \"checkout \" &&\n+\ttest_completion \"git --no-pager check\" \"checkout \" &&\n+\ttest_completion \"git --work-tree=foo check\" \"checkout \" &&\n+\ttest_completion \"git --namespace=foo check\" \"checkout \" &&\n+\ttest_completion \"git --paginate check\" \"checkout \" &&\n+\ttest_completion \"git --info-path check\" \"checkout \" &&\n+\ttest_completion \"git --no-replace-objects check\" \"checkout \"\n+'\n+\n test_done\n-- \n1.7.10.1.g1f19b8.dirty\n"},{"id":"189363","messageId":"7vfwc4zn1x.fsf@alter.siamese.dyndns.org","threadId":"30251","inReplyTo":"1334519060-2348-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH v4 0/5] completion: trivial cleanups and fixes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-04-15T21:45:46Z","receivedAt":"2012-04-15T21:45:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> Just a few simpliciations, improvements, and add some missing options.\n>\n> This series depends on the bash completion tests patch.\n\nIt looks like it addresses more or less all the issues raised\nin earlier rounds.  Will queue.\n\nThanks all.\n"}]}