]> git.ipfire.org Git - thirdparty/git.git/commitdiff
completion: add tests showing subpar switch/checkout --track logic
authorJacob Keller <jacob.keller@gmail.com>
Thu, 28 May 2020 18:10:36 +0000 (11:10 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 May 2020 19:53:24 +0000 (12:53 -0700)
When the --track option is provided to git switch or git checkout, and
no branch is specified by -c or -b, git will interpret the tracking
branch to determine the local branch name to use. This "Do What I Mean"
logic is similar but distinct from the default DWIM logic of
interpreting a unique remote branch name as a request to create and
track that branch.

For example, `git switch --track origin/master` is interpreted as
a request to create a local branch named master that is tracking
origin/master.

The current completion for git checkout in this regard is only somewhat
poor:

 $git checkout --track <TAB>
 HEAD
 master
 matching-branch
 matching-tag
 other/branch-in-other
 other/master-in-other

At least it still includes remote references. The clutter from including
all references isn't too bad.

However, git switch completion is terrible:

 $git switch --track <TAB>
 master
 matching-branch

It only shows local branches, not even allowing any form of completion
of the remote references!

Add tests which highlight the expected behavior of completing --track on
its own.

Note that when -c/-C or -b/-B are provided we do expect completing more
references, but this will be discussed in a future change that addresses
these options specifically.

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

index e8350b3e963613da640b01c6b059d61a9eeab3d6..411b19637f54d93563b22e841c8f52d9686b2ccf 100755 (executable)
@@ -1414,6 +1414,40 @@ test_expect_failure 'git checkout - with -d, complete only references' '
        EOF
 '
 
+#TODO: --track should only complete fully specified remote branches
+test_expect_failure 'git switch - with --track, complete only remote branches' '
+       test_completion "git switch --track " <<-\EOF
+       other/branch-in-other Z
+       other/master-in-other Z
+       EOF
+'
+
+#TODO: --track should only complete fully specified remote branches
+test_expect_failure 'git checkout - with --track, complete only remote branches' '
+       test_completion "git checkout --track " <<-\EOF
+       other/branch-in-other Z
+       other/master-in-other Z
+       EOF
+'
+
+test_expect_success 'git switch - with --no-track, complete only local branch names' '
+       test_completion "git switch --no-track " <<-\EOF
+       master Z
+       matching-branch Z
+       EOF
+'
+
+test_expect_success 'git checkout - with --no-track, complete only local references' '
+       test_completion "git checkout --no-track " <<-\EOF
+       HEAD Z
+       master Z
+       matching-branch Z
+       matching-tag Z
+       other/branch-in-other Z
+       other/master-in-other Z
+       EOF
+'
+
 test_expect_success 'teardown after ref completion' '
        git branch -d matching-branch &&
        git tag -d matching-tag &&