Skip to content

Commit

Permalink
completion: add tests showing subpar -c/-C startpoint completion
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jacob-keller authored and gitster committed May 28, 2020
1 parent c55b99c commit b07d77a
Showing 1 changed file with 140 additions and 0 deletions.
140 changes: 140 additions & 0 deletions t/t9902-completion.sh
Expand Up @@ -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 &&
Expand Down

0 comments on commit b07d77a

Please sign in to comment.