Re: [PATCH] worktree add: improve message for ambiguous remote branch name
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 10, 2026, 15:06 UTC
- Message-ID
- <xmqqse4m6mlz.fsf@gitster.g>
- In-Reply-To
- <CAF5D8-vkd3GOOpdaC=swLv-gxtCzkdhNNUpbTSwr2PBH_Jk=1w@mail.gmail.com>
Yoichi Nakayama <yoichi.nakayama@gmail.com> writes:
Show 10 quoted lines
> Before the change, it calles lookup_commit_reference_by_name() again
> in the if condition and die() at:
>
> if (!opts.orphan && !lookup_commit_reference_by_name(branch)) {
> /* snip */
> die(_("invalid reference: %s"), branch);
> }
>
> The motivation for the fix was that this error message did not
> accurately reflect the situation.The location of this die() is a tad away from the places that the patch touched. The proposed log message could be made a bit more helpful by mentioning it. What was posted reads:
Display a descriptive message when DWIM fails.
Add advice on how to work around this by specifying the fully
qualified name or by setting checkout.defaultRemote.but telling the readers what they will see instead of a descriptive message and how that happens would be very helpful to understand why it is a good idea to die early. Perhaps
When the user runs 'git worktree add x y z' command that does
not exactly say which remote they want to work with, we try to
guess which remote by passing y. If there are multiple remotes
that have branch named y, we silently gave up, leaving remote
still NULL. This later causes A and B not happen, and we end up
with passing an non-existing branch to
lookup_commit_reference_by_name(), triggering "invalid
reference" error and die.or something like that that describes the issue to a similar degree as above mock-up message.
Thanks.