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

[PATCH v4 1/3] completion: no-op refactoring of diff completion

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 7, 2026, 01:38 UTC
Message-ID
<20260807013830.698340-2-gitster@pobox.com>
In-Reply-To
<20260807013830.698340-1-gitster@pobox.com>

The "git diff" completion function punts very early when it sees "--" on the command line, since it is a sign that options or revisions can appear and the current completion does not need to do anything "git diff" specific. By returning, it lets Bash default action that completes the names of the files in $PWD to kick in.

In preparation for the next step to change what happens when we "punt", arrange the code flow to avoid this early return. The behaviour at this step is unchanged, but the control flow just falls straight to the end.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 contrib/completion/git-completion.bash | 61 ++++++++++++++------------
 1 file changed, 33 insertions(+), 28 deletions(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e875787710..ccd3b2a372 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1947,35 +1947,40 @@ __git_diff_difftool_options="--cached --staged
 
 _git_diff ()
 {
-	__git_has_doubledash && return
-
-	case "$cur" in
-	--diff-algorithm=*)
-		__gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
-		return
-		;;
-	--submodule=*)
-		__gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}"
-		return
-		;;
-	--color-moved=*)
-		__gitcomp "$__git_color_moved_opts" "" "${cur##--color-moved=}"
-		return
-		;;
-	--color-moved-ws=*)
-		__gitcomp "$__git_color_moved_ws_opts" "" "${cur##--color-moved-ws=}"
-		return
-		;;
-	--ws-error-highlight=*)
-		__gitcomp "$__git_ws_error_highlight_opts" "" "${cur##--ws-error-highlight=}"
-		return
-		;;
-	--*)
-		__gitcomp "$__git_diff_difftool_options"
-		return
+	if ! __git_has_doubledash; then
+		case "$cur" in
+		--diff-algorithm=*)
+			__gitcomp "$__git_diff_algorithms" \
+				"" "${cur##--diff-algorithm=}"
+			return
 		;;
-	esac
-	__git_complete_revlist_file
+		--submodule=*)
+			__gitcomp "$__git_diff_submodule_formats" \
+				"" "${cur##--submodule=}"
+			return
+			;;
+		--color-moved=*)
+			__gitcomp "$__git_color_moved_opts" \
+				"" "${cur##--color-moved=}"
+			return
+			;;
+		--color-moved-ws=*)
+			__gitcomp "$__git_color_moved_ws_opts" \
+				"" "${cur##--color-moved-ws=}"
+			return
+			;;
+		--ws-error-highlight=*)
+			__gitcomp "$__git_ws_error_highlight_opts" \
+				"" "${cur##--ws-error-highlight=}"
+			return
+			;;
+		--*)
+			__gitcomp "$__git_diff_difftool_options"
+			return
+			;;
+		esac
+		__git_complete_revlist_file
+	fi
 }
 
 __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
-- 
2.55.0-655-gb2c071042d
Previous: Junio C HamanoNext: Elijah Newren
Message 15 of 34 in “completion: complete tracked paths for 'git diff'”
  1. completion: complete tracked paths for 'git diff'Junio C Hamano, Aug 3, 2026
  2. Junio C HamanoAug 3, 2026
  3. SZEDER GáborAug 3, 2026
  4. Junio C HamanoAug 3, 2026
  5. Junio C HamanoAug 3, 2026
  6. completion: complete tracked paths for 'git diff'Junio C Hamano, Aug 4, 2026
  7. 0/3 completion of 'git [-C <dir>] diff'Junio C Hamano, Aug 5, 2026
  8. 1/3 completion: no-op refactoring of diff completionJunio C Hamano, Aug 5, 2026
  9. 2/3 completion: complete tracked paths for 'git diff'Junio C Hamano, Aug 5, 2026
  10. 3/3 completion: 'git diff' completes untracked paths as a last resortJunio C Hamano, Aug 5, 2026
  11. D. Ben KnobleAug 6, 2026
  12. Junio C HamanoAug 6, 2026
  13. D. Ben KnobleAug 6, 2026
  14. 0/3 completion of 'git [-C <dir>] diff'Junio C Hamano, Aug 7, 2026
  15. 1/3 completion: no-op refactoring of diff completionJunio C Hamano, Aug 7, 2026
  16. Elijah NewrenAug 7, 2026
  17. Junio C HamanoAug 7, 2026
  18. 3/3 completion: 'git diff' completes untracked paths as a last resortJunio C Hamano, Aug 7, 2026
  19. 2/3 completion: complete tracked paths for 'git diff'Junio C Hamano, Aug 7, 2026
  20. Elijah NewrenAug 7, 2026
  21. D. Ben KnobleAug 7, 2026
  22. Junio C HamanoAug 7, 2026
  23. Elijah NewrenAug 7, 2026
  24. Elijah NewrenAug 7, 2026
  25. D. Ben KnobleAug 7, 2026
  26. 0/3 completion of 'git [-C <dir>] diff'Junio C Hamano, Aug 7, 2026
  27. 1/3 completion: no-op refactoring of diff completionJunio C Hamano, Aug 7, 2026
  28. 2/3 completion: complete tracked paths for 'git diff'Junio C Hamano, Aug 7, 2026
  29. 3/3 completion: 'git diff' completes untracked paths as a last resortJunio C Hamano, Aug 7, 2026
  30. Elijah NewrenAug 7, 2026
  31. 0/3 completion of 'git [-C <dir>] diff'Junio C Hamano, Aug 12, 2026
  32. 1/3 completion: no-op refactoring of diff completionJunio C Hamano, Aug 12, 2026
  33. 2/3 completion: complete tracked paths for 'git diff'Junio C Hamano, Aug 12, 2026
  34. 3/3 completion: 'git diff' completes untracked paths as a last resortJunio C Hamano, Aug 12, 2026

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.