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

Re: [PATCH 0/2] completion of 'git [-C <dir>] checkout'

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 11, 2026, 04:04 UTC
Message-ID
<xmqqcxvp481b.fsf@gitster.g>
In-Reply-To
<xmqq7blx5oor.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
> Continuing from the previous 'git [-C <dir>] diff' series, these two
> patches correct completion for 'git checkout [-C <dir>] path<TAB>',
> but without falling back to untracked paths, as "checkout paths out
> of the index" is by definition about paths that appear in the index.

I suppose I will add the 'untracked, too' final fallback, just like 'diff', because 'git checkout other-branch foo<TAB>' could resurrect a path like 'foolish' that appears on 'other-branch' but not in the currently checked-out branch (and thus not in the index). The 'foolish' file might also appear in the working tree as an untracked path.

This is not particularly useful, however, as it is unlikely that a file like 'foolish' tracked on another branch would be lying around untracked in the working tree to begin with.

I did not, however, find any readily usable machinery in the 'git-completion.bash' script that allows completing a path within an arbitrary tree. If such machinery were available, 'git checkout other-branch foo<TAB>' could capture the output of 'git ls-tree -r other-branch' and offer paths that begin with the given prefix.

Regardless, implementing this is beyond my 'git-completion-fu' right now. As I mentioned, I barely managed the 'diff' completion as a monkey-see-monkey-do patch series, and I would welcome others building on top of this once the dust settles.

Show 6 quoted lines
>  1/2: completion: no-op refactoring of checkout completion
>  2/2: completion: complete tracked paths for "git checkout"
>
>  contrib/completion/git-completion.bash | 86 ++++++++++++++------------
>  t/t9902-completion.sh                  | 27 ++++++++
>  2 files changed, 73 insertions(+), 40 deletions(-)
Previous: Junio C HamanoNext: Ben Knoble
Message 6 of 19 in “completion of 'git [-C <dir>] checkout'”
  1. 0/2 completion of 'git [-C <dir>] checkout'Junio C Hamano, Aug 11, 2026
  2. 1/2 completion: no-op refactoring of checkout completionJunio C Hamano, Aug 11, 2026
  3. 2/2 completion: complete tracked paths for "git checkout"Junio C Hamano, Aug 11, 2026
  4. Ben KnobleAug 11, 2026
  5. Junio C HamanoAug 11, 2026
  6. Junio C HamanoAug 11, 2026
  7. Ben KnobleAug 11, 2026
  8. Junio C HamanoAug 12, 2026
  9. 0/3 completion of 'git [-C <dir>] checkout'Junio C Hamano, Aug 12, 2026
  10. 1/3 completion: no-op refactoring of checkout completionJunio C Hamano, Aug 12, 2026
  11. 2/3 completion: complete tracked paths for "git checkout"Junio C Hamano, Aug 12, 2026
  12. 3/3 completion: 'git checkout' completes untracked paths as a last resortJunio C Hamano, Aug 12, 2026
  13. Elijah NewrenAug 12, 2026
  14. Junio C HamanoAug 12, 2026
  15. 0/3 completion of 'git [-C <dir>] checkout'Junio C Hamano, Aug 13, 2026
  16. 1/3 completion: no-op refactoring of checkout completionJunio C Hamano, Aug 13, 2026
  17. 2/3 completion: complete tracked paths for "git checkout"Junio C Hamano, Aug 13, 2026
  18. 3/3 completion: 'git checkout' completes untracked paths as a last resortJunio C Hamano, Aug 13, 2026
  19. Elijah NewrenAug 14, 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.