Re: [PATCH] completion: complete remote branches with switch --track
- From
Jacob Keller <jacob.keller@gmail.com>
- Date
- Apr 23, 2020, 23:46 UTC
- Message-ID
- <CA+P7+xqgW0tfLcy8R4gy2X_8apvXOaibvd3XWWdKSk8yMi+4Bg@mail.gmail.com>
- In-Reply-To
- <20200423020344.GI140314@google.com>
On Wed, Apr 22, 2020 at 7:03 PM Jonathan Nieder <jrnieder@gmail.com> wrote:
> > Let me check that I understand correctly: >
I do not believe your understanding here is correct. This is about the case where you try to complete
git switch --track <TAB>
I expect this to complete to the list of all remote branches, and *not* to include local branches that already exist.
Today, on git version 2.25.2,
git switch --track <TAB> completes only to local branches.
git switch <TAB> appears to complete to basically any reference.
> If --detach is passed, the <start-point> parameter is an arbitrary > commit. So we want all refs (or even all commits), not just commits > that are eligible for "git switch --guess" (the default mode) dwimery. >
Yep, I agree here.
Show 5 quoted lines
> If --track is passed, the <start-point> parameter should be an > arbitrary remote-tracking branch, not just a remote-tracking branch > without corresponding local branch that would be eligible for --guess. > A few lines up we handle this by setting track_opt to empty. >
Sort of. Yes, we do disable "track_opt", but, because --detach is *not* set, we also set only_local_ref=y.
In this case, when only_local_ref=y, and when track_opt is not set, we trigger the call to __git_heads instead of __git_complete_refs.
I *think* the problem is that we actually got something inverted in a sense:
We probably do want git switch to complete only local branches and dwims, not arbitrary references.
Show 11 quoted lines
> If neither --detach nor --track is passed, then... > > ... I'm not sure I understand the neither --detach nor --track passed > case. Wouldn't this be --guess mode, where "$track_opt" is set, so the > value of "$only_local_ref" isn't used? Or is this about the case > where (1) --detach is not passed, (2) --track is not passed, and (3) > --no-guess or GIT_COMPLETION_CHECKOUT_NO_GUESS is passed? > > Yes, it must be about that case. In that case, only_local_ref is > right. >
that seems to behave properly, i.e.
git switch --no-guess <TAB> will complete only local branches.
> In any case, this is getting difficult to understand, so I wonder if > some refactoring is in order. >
The trouble here is that we accidentally trigger that behavior if you do
git switch --track
because we set track_opt to none, *and* we set only_local_refs to y, resulting in just calling git_heads.
I think the trouble is that __git_complete_refs prints far more than we want, so it needs some new options to avoid printing certain settings.
I *think* the problem is that --dwim lists *both* local refs *and* unique branches from remotes, and because it lists local references, we end up displaying a bunch of unnecessary refs like tags and such.
Hmm.
Thanks, Jake