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

completion: add tests showing subpar switch/checkout --track logic

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>

Jacob Keller committed May 28, 2020 at 11:10 UTC c55b99c3d3359debb8601b6f687c94deab59ad2d
1 file changed +34
t/t9902-completion.sh
+34
@@ -1414,6 +1414,40 @@ test_expect_failure 'git checkout - with -d, complete only references' '
1414 EOF
1415 '
1416
1417 +#TODO: --track should only complete fully specified remote branches
1418 +test_expect_failure 'git switch - with --track, complete only remote branches' '
1419 + test_completion "git switch --track " <<-\EOF
1420 + other/branch-in-other Z
1421 + other/master-in-other Z
1422 + EOF
1423 +'
1424 +
1425 +#TODO: --track should only complete fully specified remote branches
1426 +test_expect_failure 'git checkout - with --track, complete only remote branches' '
1427 + test_completion "git checkout --track " <<-\EOF
1428 + other/branch-in-other Z
1429 + other/master-in-other Z
1430 + EOF
1431 +'
1432 +
1433 +test_expect_success 'git switch - with --no-track, complete only local branch names' '
1434 + test_completion "git switch --no-track " <<-\EOF
1435 + master Z
1436 + matching-branch Z
1437 + EOF
1438 +'
1439 +
1440 +test_expect_success 'git checkout - with --no-track, complete only local references' '
1441 + test_completion "git checkout --no-track " <<-\EOF
1442 + HEAD Z
1443 + master Z
1444 + matching-branch Z
1445 + matching-tag Z
1446 + other/branch-in-other Z
1447 + other/master-in-other Z
1448 + EOF
1449 +'
1450 +
1451 test_expect_success 'teardown after ref completion' '
1452 git branch -d matching-branch &&
1453 git tag -d matching-tag &&