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

[PATCH 3/4] completion: disable dwim on "git switch -d"

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jun 20, 2019, 09:55 UTC
Message-ID
<20190620095523.10003-4-pclouds@gmail.com>
In-Reply-To
<20190620095523.10003-1-pclouds@gmail.com>

Even though dwim is enabled by default, it will never be done when --detached is specified. If you force "-d --guess" you will get an error because --guess then implies -c which cannot be used with -d. So we can disable dwim in "switch -d". It makes the completion list in this case a bit shorter.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 contrib/completion/git-completion.bash | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 58d18d41a2..656e49710e 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2183,6 +2183,10 @@ _git_switch ()
 		fi
 		if [ -z "$(__git_find_on_cmdline "-d --detach")" ]; then
 			only_local_ref=y
+		else
+			# --guess --detach is invalid combination, no
+			# dwim will be done when --detach is specified
+			track_opt=
 		fi
 		if [ $only_local_ref = y -a -z "$track_opt" ]; then
 			__gitcomp_direct "$(__git_heads "" "$cur" " ")"
-- 
2.22.0.rc0.322.g2b0371e29a
Previous: Duy NguyenNext: Nguyễn Thái Ngọc Duy
Message 6 of 13 in “Some more on top of nd/switch-and-restore”
  1. 0/4 Some more on top of nd/switch-and-restoreNguyễn Thái Ngọc Duy, Jun 20, 2019
  2. 1/4 t2027: use test_must_be_emptyNguyễn Thái Ngọc Duy, Jun 20, 2019
  3. 2/4 switch: allow to switch in the middle of bisectNguyễn Thái Ngọc Duy, Jun 20, 2019
  4. Derrick StoleeJun 20, 2019
  5. Duy NguyenJun 20, 2019
  6. 3/4 completion: disable dwim on "git switch -d"Nguyễn Thái Ngọc Duy, Jun 20, 2019
  7. 4/4 restore: add --intent-to-add (restoring worktree only)Nguyễn Thái Ngọc Duy, Jun 20, 2019
  8. Derrick StoleeJun 20, 2019
  9. Duy NguyenJun 20, 2019
  10. Junio C HamanoJun 26, 2019
  11. Duy NguyenJun 27, 2019
  12. Duy NguyenJun 27, 2019
  13. Junio C HamanoJun 27, 2019

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.