Re: [PATCH 0/2] completion of 'git [-C <dir>] checkout'
From: Junio C Hamano <hidden>
Date: 2026-08-11 04:04:35
Junio C Hamano [off-list ref] 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.
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(-)