Re: [PATCH v6 3/3] worktree add: improve message for ambiguous remote branch name
- From
Yoichi Nakayama <yoichi.nakayama@gmail.com>
- Date
- Aug 22, 2026, 00:50 UTC
- Message-ID
- <CAF5D8-trxeMd8HYzy6kD4myf+bynkxOvxKDQrMdmqnvcdpdkEA@mail.gmail.com>
- In-Reply-To
- <xmqqzeyfxcdu.fsf@gitster.g>
On Sat, Aug 22, 2026 at 8:49 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 16 quoted lines
> > Yoichi Nakayama <yoichi.nakayama@gmail.com> writes: > > > My initial patch included a warning and advice here, > > but now I don't think they are necessary. > > > > Even if multiple remotes match here, the command completes > > successfully. This could well be the intended behavior > > (just as when there is no match). In that case, a warning > > or advice might be superfluous. > > In other words, there is no point in calling dwim_branch() from that > code path, as the end result is exactly the same whether no remotes > match, exactly one remote matches, or two or more remotes match? > Would it then make sense to leave a note there to consider later if > the dwim_branch() call can be removed?
No. The exit codes of the command 'git worktree add ../topic-branch' are the same (== 0). but the results are different.
If there is a unique match found in dwim_branch(), it creates a local branch named topic-branch which tracks <remote>/topic-branch. In case of no match or multiple matches, it creates a local branch named topic-branch from HEAD.
Since Git treats both cases as successful, either can be considered the intended behavior. (Although, if there are multiple matches, there is a fair chance the result might not be what was intended.)
I am confident that it is appropriate to provide a hint when a command fails, but it is difficult to decide what to do when a command succeeds.
Thanks,
-- Yoichi NAKAYAMA