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

Re: [PATCH v3 3/3] completion: 'git diff' completes untracked paths as a last resort

From
D. Ben Knoble <ben.knoble@gmail.com>
Date
Aug 6, 2026, 11:30 UTC
Message-ID
<CALnO6CA8sjivVfz45OEDWnvw516z9Nd9SnC+zfJ=FK=Y6Q7MJg@mail.gmail.com>
In-Reply-To
<20260805194250.3316220-4-gitster@pobox.com>
Hello Junio,
On Wed, Aug 5, 2026 at 3:45 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 60 quoted lines
>
> 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                  | 22 +++++++++++++++++++++-
>  2 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 845fd19f70..7741789e41 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 10ac690e21..53a2bfb2ac 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -2663,6 +2663,7 @@ test_expect_success 'setup for integration tests' '
>         echo content >file1 &&
>         echo more >file2 &&
>         git add file1 file2 &&
> +       echo untracked >ufile &&
>         git commit -m one &&
>         git branch mybranch &&
>         git tag mytag
> @@ -2728,6 +2729,15 @@ test_expect_success 'git diff -- completes tracked paths' '
>         EOF
>  '
>
> +test_expect_success 'git diff [--] completes untracked paths, too' '
> +       test_completion "git diff u" <<-\EOF &&
> +       ufile
> +       EOF
> +       test_completion "git diff -- u" <<-\EOF
> +       ufile
> +       EOF
> +'
> +
LGTM up to here.
Show 14 quoted lines
>  test_expect_success 'git -C <path> diff completes tracked paths in specified repo' '
>         test_when_finished "rm -rf repo-for-diff" &&
>         git init repo-for-diff &&
> @@ -2744,11 +2754,21 @@ test_expect_success 'git -C <path> diff -- completes pathspecs in specified repo
>         test_when_finished "rm -rf repo-for-diff" &&
>         git init repo-for-diff &&
>         echo content >repo-for-diff/otherfile &&
> +       echo untracked >repo-for-diff/untracked &&
>         git -C repo-for-diff add otherfile &&
>         git -C repo-for-diff commit -m otherfile &&
> -       test_completion "git -C repo-for-diff diff -- o" <<-\EOF
> +       test_completion "git -C repo-for-diff diff o" <<-\EOF &&
> +       otherfile
> +       EOF

Here, with more context (which I won't paste, because GMail…), it looks like this test is redundant with the test just before?

Show 10 quoted lines
> +       test_completion "git -C repo-for-diff diff -- o" <<-\EOF &&
>         otherfile
>         EOF
> +       test_completion "git -C repo-for-diff diff u" <<-\EOF &&
> +       untracked
> +       EOF
> +       test_completion "git -C repo-for-diff diff -- u" <<-\EOF
> +       untracked
> +       EOF
>  '
These tests intermingle with -- and without; the other tests separated them.

I don't think I have a strong preference, but perhaps consistency is a good ideal?

-- 
D. Ben Knoble
Previous: Junio C HamanoNext: Junio C Hamano
Message 11 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.