@matheusbsbs / matheus-bagliano / commits / d773c6314d
Fork 0

bash: offer only paths after '--'

Many git commands use '--' to separate subcommands, options, and refs from paths. However, the programmable completion for several of these commands does not respect the '--', and offer subcommands, options, or refs after a '--', although only paths are permitted. e.g. 'git bisect -- <TAB>' offers subcommands, 'git log -- --<TAB>' offers options and 'git log -- git<TAB>' offers all gitgui tags. The completion for the following commands share this wrong behaviour: am add bisect commit diff log reset shortlog submodule gitk. To avoid this, we check the presence of a '--' on the command line first and let the shell do filename completion, if one is found. Signed-off-by: SZEDER Gábor <szeder@ira.uka.de> Acked-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Jul 8, 2008 at 18:56 UTC d773c6314d5660266313772b3fd8a466c3dbc559
1 file changed +30
contrib/completion/git-completion.bash
+30
@@ -451,6 +451,18 @@ __git_find_subcommand ()
451 done
452 }
453
454 +__git_has_doubledash ()
455 +{
456 + local c=1
457 + while [ $c -lt $COMP_CWORD ]; do
458 + if [ "--" = "${COMP_WORDS[c]}" ]; then
459 + return 0
460 + fi
461 + c=$((++c))
462 + done
463 + return 1
464 +}
465 +
466 __git_whitespacelist="nowarn warn error error-all strip"
467
468 _git_am ()
@@ -497,6 +509,8 @@ _git_apply ()
509
510 _git_add ()
511 {
512 + __git_has_doubledash && return
513 +
514 local cur="${COMP_WORDS[COMP_CWORD]}"
515 case "$cur" in
516 --*)
@@ -511,6 +525,8 @@ _git_add ()
525
526 _git_bisect ()
527 {
528 + __git_has_doubledash && return
529 +
530 local subcommands="start bad good reset visualize replay log"
531 local subcommand="$(__git_find_subcommand "$subcommands")"
532 if [ -z "$subcommand" ]; then
@@ -613,6 +629,8 @@ _git_cherry_pick ()
629
630 _git_commit ()
631 {
632 + __git_has_doubledash && return
633 +
634 local cur="${COMP_WORDS[COMP_CWORD]}"
635 case "$cur" in
636 --*)
@@ -632,6 +650,8 @@ _git_describe ()
650
651 _git_diff ()
652 {
653 + __git_has_doubledash && return
654 +
655 local cur="${COMP_WORDS[COMP_CWORD]}"
656 case "$cur" in
657 --*)
@@ -734,6 +754,8 @@ _git_ls_tree ()
754
755 _git_log ()
756 {
757 + __git_has_doubledash && return
758 +
759 local cur="${COMP_WORDS[COMP_CWORD]}"
760 case "$cur" in
761 --pretty=*)
@@ -1085,6 +1107,8 @@ _git_remote ()
1107
1108 _git_reset ()
1109 {
1110 + __git_has_doubledash && return
1111 +
1112 local cur="${COMP_WORDS[COMP_CWORD]}"
1113 case "$cur" in
1114 --*)
@@ -1097,6 +1121,8 @@ _git_reset ()
1121
1122 _git_shortlog ()
1123 {
1124 + __git_has_doubledash && return
1125 +
1126 local cur="${COMP_WORDS[COMP_CWORD]}"
1127 case "$cur" in
1128 --*)
@@ -1143,6 +1169,8 @@ _git_stash ()
1169
1170 _git_submodule ()
1171 {
1172 + __git_has_doubledash && return
1173 +
1174 local subcommands="add status init update"
1175 if [ -z "$(__git_find_subcommand "$subcommands")" ]; then
1176 local cur="${COMP_WORDS[COMP_CWORD]}"
@@ -1349,6 +1377,8 @@ _git ()
1377
1378 _gitk ()
1379 {
1380 + __git_has_doubledash && return
1381 +
1382 local cur="${COMP_WORDS[COMP_CWORD]}"
1383 local g="$(git rev-parse --git-dir 2>/dev/null)"
1384 local merge=""