From 08866a6d130dbe6733f54f6f5390a067b7ecf74c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 11 Aug 2026 11:41:41 -0700 Subject: [PATCH] Revert "Merge branch 'yn/worktree-add-no-dwim-with-b' into next" This reverts commit 9d682832cd44d4d2338d60163dfb166bf06a0ff2, reversing changes made to bb960508411f41af160bae98aed1e753eb0bdcc9 to take yet another reroll. --- builtin/worktree.c | 20 +++++++++----------- t/t2400-worktree-add.sh | 10 ---------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/builtin/worktree.c b/builtin/worktree.c index cc46c1b415..654d27c3e1 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -898,18 +898,16 @@ 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) { - if (!new_branch) { - struct object_id oid; - struct commit *commit; - char *remote; + 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; - } + 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; } } diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index ba3bec078f..87b926728a 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -621,16 +621,6 @@ test_expect_success '"add" dwims' ' ) ' -test_expect_success '"add" 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" dwims with checkout.defaultRemote' ' test_when_finished rm -rf repo_upstream repo_dwim foo && setup_remote_repo repo_upstream repo_dwim &&