]> git.ipfire.org Git - thirdparty/git.git/commitdiff
completion: add tests showing subpar -c/-C startpoint completion
authorJacob Keller <jacob.keller@gmail.com>
Thu, 28 May 2020 18:10:37 +0000 (11:10 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 28 May 2020 19:53:24 +0000 (12:53 -0700)
When using the branch creation argument for git switch or git checkout,
-c/-C or -b/-B, the commands operate in a different mode: `git switch -c
<branch> <some-reference>` means to create a branch named <branch> at
the commit referred to by <some-reference>.

When completing the start-point, we ought to always complete all valid
references.

Add tests for the completion of the start-point to -c/-C and -b/-B.

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

index 411b19637f54d93563b22e841c8f52d9686b2ccf..4b506eb81f1eb43813a53aade087439dcd6778b8 100755 (executable)
@@ -1448,6 +1448,146 @@ test_expect_success 'git checkout - with --no-track, complete only local referen
        EOF
 '
 
+#TODO: completing the start point of -c/-C should not include DWIM references
+test_expect_failure 'git switch - with -c, complete all references' '
+       test_completion "git switch -c new-branch " <<-\EOF
+       HEAD Z
+       master Z
+       matching-branch Z
+       matching-tag Z
+       other/branch-in-other Z
+       other/master-in-other Z
+       EOF
+'
+
+#TODO: completing the start point of -c/-C should not include DWIM references
+test_expect_failure 'git switch - with -C, complete all references' '
+       test_completion "git switch -C new-branch " <<-\EOF
+       HEAD Z
+       master Z
+       matching-branch Z
+       matching-tag Z
+       other/branch-in-other Z
+       other/master-in-other Z
+       EOF
+'
+
+#TODO: completing the start point of -c/-C should include all references, not just local branches
+test_expect_failure 'git switch - with -c and --track, complete all references' '
+       test_completion "git switch -c new-branch --track " <<-EOF
+       HEAD Z
+       master Z
+       matching-branch Z
+       matching-tag Z
+       other/branch-in-other Z
+       other/master-in-other Z
+       EOF
+'
+
+#TODO: completing the start point of -c/-C should include all references, not just local branches
+test_expect_failure 'git switch - with -C and --track, complete all references' '
+       test_completion "git switch -C new-branch --track " <<-EOF
+       HEAD Z
+       master Z
+       matching-branch Z
+       matching-tag Z
+       other/branch-in-other Z
+       other/master-in-other Z
+       EOF
+'
+
+#TODO: completing the start point of -c/-C should include all references, not just local branches
+test_expect_failure 'git switch - with -c and --no-track, complete all references' '
+       test_completion "git switch -c new-branch --no-track " <<-\EOF
+       HEAD Z
+       master Z
+       matching-branch Z
+       matching-tag Z
+       other/branch-in-other Z
+       other/master-in-other Z
+       EOF
+'
+
+#TODO: completing the start point of -c/-C should include all references, not just local branches
+test_expect_failure 'git switch - with -C and --no-track, complete all references' '
+       test_completion "git switch -C new-branch --no-track " <<-\EOF
+       HEAD Z
+       master Z
+       matching-branch Z
+       matching-tag Z
+       other/branch-in-other Z
+       other/master-in-other Z
+       EOF
+'
+
+#TODO: completing the start point of -b/-B should not include DWIM references
+test_expect_failure 'git checkout - with -b, complete all references' '
+       test_completion "git checkout -b new-branch " <<-\EOF
+       HEAD Z
+       master Z
+       matching-branch Z
+       matching-tag Z
+       other/branch-in-other Z
+       other/master-in-other Z
+       EOF
+'
+
+#TODO: completing the start point of -b/-B should not include DWIM references
+test_expect_failure 'git checkout - with -B, complete all references' '
+       test_completion "git checkout -B new-branch " <<-\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 'git checkout - with -b and --track, complete all references' '
+       test_completion "git checkout -b new-branch --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 'git checkout - with -B and --track, complete all references' '
+       test_completion "git checkout -B new-branch --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 'git checkout - with -b and --no-track, complete all references' '
+       test_completion "git checkout -b new-branch --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 'git checkout - with -B and --no-track, complete all references' '
+       test_completion "git checkout -B new-branch --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 &&