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

Re: [PATCH] completion: complete tracked paths for 'git diff'

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 3, 2026, 13:41 UTC
Message-ID
<xmqq33wv1fts.fsf@gitster.g>
In-Reply-To
<anAqfqcEueSKmAH+@szeder.dev>
SZEDER Gábor <szeder.dev@gmail.com> writes:
Show 5 quoted lines
> I think we should check whether the '--no-index' option is present on
> the command line, and simply not call __git_complete_index_file() if
> it is, to let Bash list all paths; i.e. each of those calls should be
> protected by an additional 'if test -z "$(__git_find_on_cmdline
> "--no-index")' condition, perhaps.

Ah, I did not think of the "we made 'git diff' work without Git" mode at all.

But I would avoid scanning the command line for '--no-index' for two reasons:

 (1) "git diff -S --no-index maint master" would not give you the
     '--no-index' mode.
 (2) When run outside the working tree of a repository, you do not
     have to say '--no-index'.

These make detecting the "'git diff' but not Git" mode tedious and error-prone.

I have not tried this, but if we arranged the code to fall back further to Bash-native "paths in $PWD" after the completion code in the posted patch found nothing, would it be sufficient?

When trying to complete an untracked file in the working tree of a repository, if the file shares the same prefix with a tracked file, you cannot complete the untracked file without a prefix long enough to disambiguate it from the tracked one. Such a prefix may not even exist (e.g., 'foo' is tracked and 'foo~' is untracked; when you type "git diff --no-index foo<TAB>", you get 'foo' but not 'foo~', so you end up typing 'foo~' in full). In that sense, it is a regression, but supporting Git usage is the primary mission of 'git diff', so the trade-off may not be so bad.

Thoughts?
Previous: SZEDER GáborNext: Junio C Hamano
Message 4 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.