@matheusbsbs / matheus-bagliano / commits / 7f59d60429
Fork 0

completion: add tests showing subpar -c/C argument completion

When using the branch creation argument for git switch or git checkout (-c/-C or -b/-B), the commands switch to a different mode: `git switch -c <branch> <some-referance>` means to create a branch named <branch> at the commit referred to by <some-reference>. When completing git switch or git checkout, it makes sense to complete the branch name differently from the start point. When completing a branch, one might consider that we do not have anything worth completing. After all, a new branch must have an entirely new name. Consider, however, that if a user names branches using some similar scheme, they might wish to name a new branch by modifying the name of an existing branch. To avoid overloading completion for the argument, it seems reasonable to complete only the local branch names and the valid "Do What I Mean" remote branch names. Add tests for the completion of the argument to -c/-C and -b/-B, highlighting this preferred completion behavior. 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 7f59d604292774a2c5c79a644419a9aa6c720365
1 file changed +100
t/t9902-completion.sh
+100
@@ -1588,6 +1588,106 @@ test_expect_success 'git checkout - with -B and --no-track, complete all referen
1588 EOF
1589 '
1590
1591 +#TODO: -c/-C argument completion should not include all references
1592 +test_expect_failure 'git switch - for -c, complete local branches and unique remote branches' '
1593 + test_completion "git switch -c " <<-\EOF
1594 + branch-in-other Z
1595 + master Z
1596 + master-in-other Z
1597 + matching-branch Z
1598 + EOF
1599 +'
1600 +
1601 +#TODO: -c/-C argument completion should not include all references
1602 +test_expect_failure 'git switch - for -C, complete local branches and unique remote branches' '
1603 + test_completion "git switch -C " <<-\EOF
1604 + branch-in-other Z
1605 + master Z
1606 + master-in-other Z
1607 + matching-branch Z
1608 + EOF
1609 +'
1610 +
1611 +test_expect_success 'git switch - for -c with --no-guess, complete local branches only' '
1612 + test_completion "git switch --no-guess -c " <<-\EOF
1613 + master Z
1614 + matching-branch Z
1615 + EOF
1616 +'
1617 +
1618 +test_expect_success 'git switch - for -C with --no-guess, complete local branches only' '
1619 + test_completion "git switch --no-guess -C " <<-\EOF
1620 + master Z
1621 + matching-branch Z
1622 + EOF
1623 +'
1624 +
1625 +test_expect_success 'git switch - for -c with --no-track, complete local branches only' '
1626 + test_completion "git switch --no-track -c " <<-\EOF
1627 + master Z
1628 + matching-branch Z
1629 + EOF
1630 +'
1631 +
1632 +test_expect_success 'git switch - for -C with --no-track, complete local branches only' '
1633 + test_completion "git switch --no-track -C " <<-\EOF
1634 + master Z
1635 + matching-branch Z
1636 + EOF
1637 +'
1638 +
1639 +#TODO: -b/-B argument completion should not include all references
1640 +test_expect_failure 'git checkout - for -b, complete local branches and unique remote branches' '
1641 + test_completion "git checkout -b " <<-\EOF
1642 + branch-in-other Z
1643 + master Z
1644 + master-in-other Z
1645 + matching-branch Z
1646 + EOF
1647 +'
1648 +
1649 +#TODO: -b/-B argument completion should not include all references
1650 +test_expect_failure 'git checkout - for -B, complete local branches and unique remote branches' '
1651 + test_completion "git checkout -B " <<-\EOF
1652 + branch-in-other Z
1653 + master Z
1654 + master-in-other Z
1655 + matching-branch Z
1656 + EOF
1657 +'
1658 +
1659 +#TODO: -b/-B argument completion should not include all references
1660 +test_expect_failure 'git checkout - for -b with --no-guess, complete local branches only' '
1661 + test_completion "git checkout --no-guess -b " <<-\EOF
1662 + master Z
1663 + matching-branch Z
1664 + EOF
1665 +'
1666 +
1667 +#TODO: -b/-B argument completion should not include all references
1668 +test_expect_failure 'git checkout - for -B with --no-guess, complete local branches only' '
1669 + test_completion "git checkout --no-guess -B " <<-\EOF
1670 + master Z
1671 + matching-branch Z
1672 + EOF
1673 +'
1674 +
1675 +#TODO: -b/-B argument completion should not include all references
1676 +test_expect_failure 'git checkout - for -b with --no-track, complete local branches only' '
1677 + test_completion "git checkout --no-track -b " <<-\EOF
1678 + master Z
1679 + matching-branch Z
1680 + EOF
1681 +'
1682 +
1683 +#TODO: -b/-B argument completion should not include all references
1684 +test_expect_failure 'git checkout - for -B with --no-track, complete local branches only' '
1685 + test_completion "git checkout --no-track -B " <<-\EOF
1686 + master Z
1687 + matching-branch Z
1688 + EOF
1689 +'
1690 +
1691 test_expect_success 'teardown after ref completion' '
1692 git branch -d matching-branch &&
1693 git tag -d matching-tag &&