]> git.ipfire.org Git - thirdparty/git.git/commitdiff
completion: improve handling of --detach in checkout
authorJacob Keller <jacob.keller@gmail.com>
Thu, 28 May 2020 18:10:45 +0000 (11:10 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 May 2020 19:57:07 +0000 (12:57 -0700)
Just like git switch, we should not complete DWIM remote branch names
if --detach has been specified. To avoid this, refactor _git_checkout in
a similar way to _git_switch.

Note that we don't simply clear dwim_opt when we find -d or --detach, as
we will be adding other modes and checks, making this flow easier to
follow.

Update the previously failing tests to show that the breakage has been
resolved.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash
t/t9902-completion.sh

index 19d08828b6d17c10037444e628d623595f26b6f6..56480371ffba090ba21fec668c45dbe1672f0778 100644 (file)
@@ -1489,7 +1489,12 @@ _git_checkout ()
                ;;
        *)
                local dwim_opt="$(__git_checkout_default_dwim_mode)"
-               __git_complete_refs $dwim_opt
+
+               if [ -n "$(__git_find_on_cmdline "-d --detach")" ]; then
+                       __git_complete_refs --mode="refs"
+               else
+                       __git_complete_refs $dwim_opt --mode="refs"
+               fi
                ;;
        esac
 }
index 0872f8b9d79cc3b9bd38c277087258117a04f322..25d530a8b9c93aaa2c58de6ef3c677be24a0975f 100755 (executable)
@@ -1371,8 +1371,7 @@ test_expect_success 'git switch - with --detach, complete all references' '
        EOF
 '
 
-#TODO: checkout --detach incorrectly includes DWIM remote branch names
-test_expect_failure 'git checkout - with --detach, complete only references' '
+test_expect_success 'git checkout - with --detach, complete only references' '
        test_completion "git checkout --detach " <<-\EOF
        HEAD Z
        master Z
@@ -1394,8 +1393,7 @@ test_expect_success 'git switch - with -d, complete all references' '
        EOF
 '
 
-#TODO: checkout -d incorrectly includes DWIM remote branch names
-test_expect_failure 'git checkout - with -d, complete only references' '
+test_expect_success 'git checkout - with -d, complete only references' '
        test_completion "git checkout -d " <<-\EOF
        HEAD Z
        master Z