git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 06/16] completion: add tests showing subpar -c/C argument completion

From
Jacob Keller <jacob.e.keller@intel.com>
Date
May 28, 2020, 18:10 UTC
Message-ID
<20200528181048.3509470-7-jacob.e.keller@intel.com>
In-Reply-To
<20200528181048.3509470-1-jacob.e.keller@intel.com>
From: Jacob Keller <jacob.keller@gmail.com>

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>
---
 t/t9902-completion.sh | 100 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 100 insertions(+)
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 609981244e9b..63daf43b89ec 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -1588,6 +1588,106 @@ test_expect_success 'git checkout - with -B and --no-track, complete all referen
 	EOF
 '
 
+#TODO: -c/-C argument completion should not include all references
+test_expect_failure 'git switch - for -c, complete local branches and unique remote branches' '
+	test_completion "git switch -c " <<-\EOF
+	branch-in-other Z
+	master Z
+	master-in-other Z
+	matching-branch Z
+	EOF
+'
+
+#TODO: -c/-C argument completion should not include all references
+test_expect_failure 'git switch - for -C, complete local branches and unique remote branches' '
+	test_completion "git switch -C " <<-\EOF
+	branch-in-other Z
+	master Z
+	master-in-other Z
+	matching-branch Z
+	EOF
+'
+
+test_expect_success 'git switch - for -c with --no-guess, complete local branches only' '
+	test_completion "git switch --no-guess -c " <<-\EOF
+	master Z
+	matching-branch Z
+	EOF
+'
+
+test_expect_success 'git switch - for -C with --no-guess, complete local branches only' '
+	test_completion "git switch --no-guess -C " <<-\EOF
+	master Z
+	matching-branch Z
+	EOF
+'
+
+test_expect_success 'git switch - for -c with --no-track, complete local branches only' '
+	test_completion "git switch --no-track -c " <<-\EOF
+	master Z
+	matching-branch Z
+	EOF
+'
+
+test_expect_success 'git switch - for -C with --no-track, complete local branches only' '
+	test_completion "git switch --no-track -C " <<-\EOF
+	master Z
+	matching-branch Z
+	EOF
+'
+
+#TODO: -b/-B argument completion should not include all references
+test_expect_failure 'git checkout - for -b, complete local branches and unique remote branches' '
+	test_completion "git checkout -b " <<-\EOF
+	branch-in-other Z
+	master Z
+	master-in-other Z
+	matching-branch Z
+	EOF
+'
+
+#TODO: -b/-B argument completion should not include all references
+test_expect_failure 'git checkout - for -B, complete local branches and unique remote branches' '
+	test_completion "git checkout -B " <<-\EOF
+	branch-in-other Z
+	master Z
+	master-in-other Z
+	matching-branch Z
+	EOF
+'
+
+#TODO: -b/-B argument completion should not include all references
+test_expect_failure 'git checkout - for -b with --no-guess, complete local branches only' '
+	test_completion "git checkout --no-guess -b " <<-\EOF
+	master Z
+	matching-branch Z
+	EOF
+'
+
+#TODO: -b/-B argument completion should not include all references
+test_expect_failure 'git checkout - for -B with --no-guess, complete local branches only' '
+	test_completion "git checkout --no-guess -B " <<-\EOF
+	master Z
+	matching-branch Z
+	EOF
+'
+
+#TODO: -b/-B argument completion should not include all references
+test_expect_failure 'git checkout - for -b with --no-track, complete local branches only' '
+	test_completion "git checkout --no-track -b " <<-\EOF
+	master Z
+	matching-branch Z
+	EOF
+'
+
+#TODO: -b/-B argument completion should not include all references
+test_expect_failure 'git checkout - for -B with --no-track, complete local branches only' '
+	test_completion "git checkout --no-track -B " <<-\EOF
+	master Z
+	matching-branch Z
+	EOF
+'
+
 test_expect_success 'teardown after ref completion' '
 	git branch -d matching-branch &&
 	git tag -d matching-tag &&
-- 
2.25.2
Previous: Jacob KellerNext: Jacob Keller
Message 16 of 17 in “improve switch/checkout completion”
  1. 00/16 improve switch/checkout completionJacob Keller, May 28, 2020
  2. 10/16 completion: perform DWIM logic directly in __git_complete_refsJacob Keller, May 28, 2020
  3. 08/16 completion: replace overloaded track term for __git_complete_refsJacob Keller, May 28, 2020
  4. 09/16 completion: extract function __git_dwim_remote_headsJacob Keller, May 28, 2020
  5. 14/16 completion: improve handling of --track in switch/checkoutJacob Keller, May 28, 2020
  6. 16/16 completion: improve handling of --orphan option of switch/checkoutJacob Keller, May 28, 2020
  7. 12/16 completion: improve completion for git switch with no optionsJacob Keller, May 28, 2020
  8. 07/16 completion: add tests showing subpar switch/checkout --orphan logicJacob Keller, May 28, 2020
  9. 11/16 completion: improve handling of DWIM mode for switch/checkoutJacob Keller, May 28, 2020
  10. 03/16 completion: add tests showing subar checkout --detach logicJacob Keller, May 28, 2020
  11. 04/16 completion: add tests showing subpar switch/checkout --track logicJacob Keller, May 28, 2020
  12. 02/16 completion: add tests showing subpar DWIM logic for switch/checkoutJacob Keller, May 28, 2020
  13. 01/16 completion: add test showing subpar git switch completionJacob Keller, May 28, 2020
  14. 13/16 completion: improve handling of --detach in checkoutJacob Keller, May 28, 2020
  15. 05/16 completion: add tests showing subpar -c/-C startpoint completionJacob Keller, May 28, 2020
  16. 06/16 completion: add tests showing subpar -c/C argument completionJacob Keller, May 28, 2020
  17. 15/16 completion: improve handling of -c/-C and -b/-B in switch/checkoutJacob Keller, May 28, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.