From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: "Philippe Blain" <levraiphilippeblain@gmail.com>,
"Britton Leo Kerin" <britton.kerin@gmail.com>,
"Elijah Newren" <newren@gmail.com>,
"Rubén Justo" <rjusto@gmail.com>,
"Patrick Steinhardt" <ps@pks.im>,
"D. Ben Knoble" <ben.knoble@gmail.com>,
"SZEDER Gábor" <szeder.dev@gmail.com>
Subject: [PATCH v6 3/3] completion: 'git diff' completes untracked paths as a last resort
Date: Wed, 12 Aug 2026 09:25:51 -0700 [thread overview]
Message-ID: <20260812162551.2229680-4-gitster@pobox.com> (raw)
In-Reply-To: <20260812162551.2229680-1-gitster@pobox.com>
We taught 'git diff' to first try to complete revisions (unless '--'
is present on the command line) and, failing that, to complete
tracked paths. If this yields nothing, it lets the Bash default,
which offers paths in $PWD, kick in.
Teach it to complete untracked paths before giving up and letting
the Bash default kick in. With this change,
$ git -C another-directory diff un<TAB>
finds the 'untracked' file in another-directory and offers it as a
completion candidate.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
contrib/completion/git-completion.bash | 4 ++++
t/t9902-completion.sh | 20 +++++++++++++++++++-
2 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 76181e8714..d35b4f3024 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -1985,6 +1985,10 @@ _git_diff ()
if [ ${#COMPREPLY[@]} -eq 0 ]; then
__git_complete_index_file ""
fi
+
+ if [ ${#COMPREPLY[@]} -eq 0 ]; then
+ __git_complete_index_file "--others --directory"
+ fi
}
__git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 32e5d484c7..b889ec8c77 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -2664,6 +2664,7 @@ test_expect_success 'setup for integration tests' '
echo more >file2 &&
git add file1 file2 &&
echo untracked >file3 &&
+ echo untracked >ufile &&
git commit -m one &&
git branch mybranch &&
git tag mytag
@@ -2726,6 +2727,16 @@ test_expect_success 'git diff completes tracked paths when no refs match' '
EOF
'
+test_expect_success 'git diff [--] completes untracked paths, too' '
+ # ufile is not tracked and there is no ref that begins with u
+ test_completion "git diff u" <<-\EOF &&
+ ufile
+ EOF
+ test_completion "git diff -- u" <<-\EOF
+ ufile
+ EOF
+'
+
test_expect_success 'git -C <path> diff completes paths in specified repo' '
test_when_finished "rm -rf repo-for-diff" &&
git init repo-for-diff &&
@@ -2735,6 +2746,7 @@ test_expect_success 'git -C <path> diff completes paths in specified repo' '
git -C repo-for-diff add lostfile &&
git -C repo-for-diff commit -m otherfile &&
echo untracked >repo-for-diff/oops &&
+ echo untracked >repo-for-diff/ufile &&
rm -f repo-for-diff/lostfile &&
test_completion "git -C repo-for-diff diff o" <<-\EOF &&
@@ -2743,13 +2755,19 @@ test_expect_success 'git -C <path> diff completes paths in specified repo' '
test_completion "git -C repo-for-diff diff l" <<-\EOF &&
lostfile
EOF
+ test_completion "git -C repo-for-diff diff u" <<-\EOF &&
+ ufile
+ EOF
test_completion "git -C repo-for-diff diff -- o" <<-\EOF &&
otherfile
EOF
- test_completion "git -C repo-for-diff diff -- l" <<-\EOF
+ test_completion "git -C repo-for-diff diff -- l" <<-\EOF &&
lostfile
EOF
+ test_completion "git -C repo-for-diff diff -- u" <<-\EOF
+ ufile
+ EOF
'
test_expect_success 'show completes all refs' '
--
2.55.0-721-gd75157efe4
prev parent reply other threads:[~2026-08-12 16:25 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 0:58 [PATCH] completion: complete tracked paths for 'git diff' Junio C Hamano
2026-08-03 1:07 ` Junio C Hamano
2026-08-03 5:44 ` SZEDER Gábor
2026-08-03 13:41 ` Junio C Hamano
2026-08-03 15:45 ` Junio C Hamano
2026-08-04 16:22 ` [PATCH v2] " Junio C Hamano
2026-08-05 19:42 ` [PATCH v3 0/3] completion of 'git [-C <dir>] diff' Junio C Hamano
2026-08-05 19:42 ` [PATCH v3 1/3] completion: no-op refactoring of diff completion Junio C Hamano
2026-08-05 19:42 ` [PATCH v3 2/3] completion: complete tracked paths for 'git diff' Junio C Hamano
2026-08-05 19:42 ` [PATCH v3 3/3] completion: 'git diff' completes untracked paths as a last resort Junio C Hamano
2026-08-06 11:30 ` D. Ben Knoble
2026-08-06 15:06 ` Junio C Hamano
2026-08-06 11:30 ` [PATCH v3 0/3] completion of 'git [-C <dir>] diff' D. Ben Knoble
2026-08-07 1:38 ` [PATCH v4 " Junio C Hamano
2026-08-07 1:38 ` [PATCH v4 1/3] completion: no-op refactoring of diff completion Junio C Hamano
2026-08-07 6:15 ` Elijah Newren
2026-08-07 15:09 ` Junio C Hamano
2026-08-07 1:38 ` [PATCH v4 2/3] completion: complete tracked paths for 'git diff' Junio C Hamano
2026-08-07 6:18 ` Elijah Newren
2026-08-07 11:02 ` D. Ben Knoble
2026-08-07 15:13 ` Junio C Hamano
2026-08-07 15:22 ` Elijah Newren
2026-08-07 1:38 ` [PATCH v4 3/3] completion: 'git diff' completes untracked paths as a last resort Junio C Hamano
2026-08-07 6:31 ` [PATCH v4 0/3] completion of 'git [-C <dir>] diff' Elijah Newren
2026-08-07 11:05 ` D. Ben Knoble
2026-08-07 16:19 ` [PATCH v5 " Junio C Hamano
2026-08-07 16:19 ` [PATCH v5 1/3] completion: no-op refactoring of diff completion Junio C Hamano
2026-08-07 16:19 ` [PATCH v5 2/3] completion: complete tracked paths for 'git diff' Junio C Hamano
2026-08-07 16:19 ` [PATCH v5 3/3] completion: 'git diff' completes untracked paths as a last resort Junio C Hamano
2026-08-07 16:53 ` [PATCH v5 0/3] completion of 'git [-C <dir>] diff' Elijah Newren
2026-08-12 16:25 ` [PATCH v6 " Junio C Hamano
2026-08-12 16:25 ` [PATCH v6 1/3] completion: no-op refactoring of diff completion Junio C Hamano
2026-08-12 16:25 ` [PATCH v6 2/3] completion: complete tracked paths for 'git diff' Junio C Hamano
2026-08-12 16:25 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260812162551.2229680-4-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=ben.knoble@gmail.com \
--cc=britton.kerin@gmail.com \
--cc=git@vger.kernel.org \
--cc=levraiphilippeblain@gmail.com \
--cc=newren@gmail.com \
--cc=ps@pks.im \
--cc=rjusto@gmail.com \
--cc=szeder.dev@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.