Re: [PATCH 2/2] completion: complete tracked paths for "git checkout"
Ben Knoble <[email protected]>
| Newsgroups | org.kernel.vger.git |
|---|---|
| Message-ID | <[email protected]> |
> > Le 10 août 2026 à 23:21, Junio C Hamano <[email protected]> a écrit : > > When completing arguments for "git checkout", _git_checkout() > delegates to __git_complete_refs(), which only completes revision > references. This is good, as mixing revisions and paths in a single > list from which the user can choose is confusing. However, if no > reference matches, or if "--" is given, _git_checkout() leaves > COMPREPLY empty. Bash then falls back to the default filename > completion in $PWD. > > This fails when "git -C <path>" is used, as $PWD is not the target > repository. > > Update _git_checkout() to use __git_complete_index_file() when "--" > is present, or when revision reference completion yields no matching > candidates, so that tracked paths are offered as candidates. > > Signed-off-by: Junio C Hamano <[email protected]> > --- > contrib/completion/git-completion.bash | 4 ++++ > t/t9902-completion.sh | 27 ++++++++++++++++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash > index 38dec1cabe..bd4b6e9247 100644 > --- a/contrib/completion/git-completion.bash > +++ b/contrib/completion/git-completion.bash > @@ -1780,6 +1780,10 @@ _git_checkout () > ;; > esac > fi > + > + if [ ${#COMPREPLY[@]} -eq 0 ]; then > + __git_complete_index_file > + fi > } Assuming the prior step was purely mechanical, which I did not validate, this looks reasonable to me.