From: Junio C Hamano Date: Fri, 07 Aug 2026 16:19:53 GMT Subject: [PATCH v5 0/3] completion of 'git [-C ] diff' Message-ID: <20260807161956.1004889-1-gitster@pobox.com> In-Reply-To: The primary motivation for this topic is that the command-line completion of 'git diff' does not handle paths (unlike 'git status' and 'git add') and instead relies on the default behavior of Bash command-line completion, which completes files in $PWD; this does not work at all with the '-C ' option. This series teaches the completion machinery to complete revisions (unless '--' exists), then tracked paths, and then untracked paths, before letting the Bash default kick in. This way, we correctly complete 'git diff' command line even when '-C ' is in effect. The v5 iteration addresses two points identified by Elijah in v4. Hopefully this will be the "small and final" reroll. 1/3: completion: no-op refactoring of diff completion 2/3: completion: complete tracked paths for 'git diff' 3/3: completion: 'git diff' completes untracked paths as a last resort contrib/completion/git-completion.bash | 69 +++++++++++++++----------- t/t9902-completion.sh | 59 ++++++++++++++++++++++ 2 files changed, 100 insertions(+), 28 deletions(-) Range-diff against v4: 1: d3c51c042c ! 1: 8295035d13 completion: no-op refactoring of diff completion @@ contrib/completion/git-completion.bash: __git_diff_difftool_options="--cached -- - --*) - __gitcomp "$__git_diff_difftool_options" - return +- ;; +- esac +- __git_complete_revlist_file + 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=}" 2: c3658d6ca2 ! 2: dbb14298c1 completion: complete tracked paths for 'git diff' @@ contrib/completion/git-completion.bash: _git_diff () fi + + if [ ${#COMPREPLY[@]} -eq 0 ]; then -+ __git_complete_index_file ++ __git_complete_index_file "" + fi } 3: ba5dc6f164 ! 3: d661a1a5dd completion: 'git diff' completes untracked paths as a last resort @@ Commit message ## contrib/completion/git-completion.bash ## @@ contrib/completion/git-completion.bash: _git_diff () if [ ${#COMPREPLY[@]} -eq 0 ]; then - __git_complete_index_file + __git_complete_index_file "" fi + + if [ ${#COMPREPLY[@]} -eq 0 ]; then -- 2.55.0-655-g8b87133eb9