From: Junio C Hamano <gitster@pobox.com>
To: "Yoichi NAKAYAMA via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Jacob Abel <jacobabel@nullpo.dev>,
Yoichi Nakayama <yoichi.nakayama@gmail.com>
Subject: Re: [PATCH v4] worktree add: shouldn't dwim if -b or -B is given
Date: Thu, 20 Aug 2026 10:34:55 -0700 [thread overview]
Message-ID: <xmqqecfssnk0.fsf@gitster.g> (raw)
In-Reply-To: <pull.2192.v4.git.1787221888406.gitgitgadget@gmail.com> (Yoichi NAKAYAMA via GitGitGadget's message of "Thu, 20 Aug 2026 10:31:28 +0000")
"Yoichi NAKAYAMA via GitGitGadget" <gitgitgadget@gmail.com> writes:
> @@ builtin/worktree.c: static int add(int ac, const char **av, const char *prefix,
> +
> /* DWIM: Infer --orphan when repo has no refs. */
> opts.orphan = (!s) && dwim_orphan(&opts, !!opt_track, 1);
> ++ } else if (ac == 2 && new_branch) {
> ++ if (!strcmp(branch, "HEAD"))
> ++ can_use_local_refs(&opts);
> } else if (ac == 2) {
> -- struct object_id oid;
> -- struct commit *commit;
> -- char *remote;
> --
> -- commit = lookup_commit_reference_by_name(branch);
> -- if (!commit) {
> -- remote = unique_tracking_name(branch, &oid, NULL);
> -- if (remote) {
> -- new_branch = branch;
> -- branch = new_branch_to_free = remote;
> -+ if (!new_branch) {
> -+ struct object_id oid;
> -+ struct commit *commit;
> -+ char *remote;
> -+
> -+ commit = lookup_commit_reference_by_name(branch);
> -+ if (!commit) {
> -+ remote = unique_tracking_name(branch, &oid, NULL);
> -+ if (remote) {
> -+ new_branch = branch;
> -+ branch = new_branch_to_free = remote;
> -+ }
> - }
> - }
> -
> + struct object_id oid;
> + struct commit *commit;
>
> ## t/t2400-worktree-add.sh ##
> @@ t/t2400-worktree-add.sh: test_expect_success '"add" <path> <branch> dwims' '
>
>
> builtin/worktree.c | 3 +++
> t/t2400-worktree-add.sh | 10 ++++++++++
> 2 files changed, 13 insertions(+)
>
> diff --git a/builtin/worktree.c b/builtin/worktree.c
> index 654d27c3e1..15a1c9624a 100644
> --- a/builtin/worktree.c
> +++ b/builtin/worktree.c
> @@ -897,6 +897,9 @@ static int add(int ac, const char **av, const char *prefix,
>
> /* DWIM: Infer --orphan when repo has no refs. */
> opts.orphan = (!s) && dwim_orphan(&opts, !!opt_track, 1);
> + } else if (ac == 2 && new_branch) {
> + if (!strcmp(branch, "HEAD"))
> + can_use_local_refs(&opts);
> } else if (ac == 2) {
> struct object_id oid;
> struct commit *commit;
Ah, that is a much smaller patch, and does not share the same issue
as the very initial iteration.
Will queue. Thanks.
> diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
> index 87b926728a..ba3bec078f 100755
> --- a/t/t2400-worktree-add.sh
> +++ b/t/t2400-worktree-add.sh
> @@ -621,6 +621,16 @@ test_expect_success '"add" <path> <branch> dwims' '
> )
> '
>
> +test_expect_success '"add" <path> <branch> does not dwim with -b' '
> + test_when_finished rm -rf repo_upstream repo_dwim wt &&
> + setup_remote_repo repo_upstream repo_dwim &&
> + (
> + cd repo_dwim &&
> + test_must_fail git worktree add -b branch ../wt foo 2>actual &&
> + test_grep "^fatal: invalid reference: foo" actual
> + )
> +'
> +
> test_expect_success '"add" <path> <branch> dwims with checkout.defaultRemote' '
> test_when_finished rm -rf repo_upstream repo_dwim foo &&
> setup_remote_repo repo_upstream repo_dwim &&
>
> base-commit: dea0ea3582e6980ddbc1173cc8e3e9f9db91cde0
prev parent reply other threads:[~2026-08-20 17:34 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 14:00 [PATCH] worktree add: shouldn't dwim if -b or -B is given Yoichi NAKAYAMA via GitGitGadget
2026-08-04 17:11 ` Junio C Hamano
2026-08-05 10:57 ` Yoichi Nakayama
2026-08-05 12:16 ` [PATCH v2] " Yoichi NAKAYAMA via GitGitGadget
2026-08-05 12:30 ` Yoichi Nakayama
2026-08-19 22:01 ` Yoichi Nakayama
2026-08-05 12:54 ` [PATCH v3] " Yoichi NAKAYAMA via GitGitGadget
2026-08-05 16:58 ` Junio C Hamano
2026-08-20 10:31 ` [PATCH v4] " Yoichi NAKAYAMA via GitGitGadget
2026-08-20 17:34 ` Junio C Hamano [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqecfssnk0.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=jacobabel@nullpo.dev \
--cc=yoichi.nakayama@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.