diff options
| author | Junio C Hamano <gitster@pobox.com> | 2026-08-31 08:24:58 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-08-31 08:24:58 -0700 |
| commit | 9321f5936a11d43a666244b4a1737f231469ef7b (patch) | |
| tree | 651f366d3d453afe2dd4714ea3f271efd511ec1d | |
| parent | c73e85354c275c9d409b26445089bc16940fc527 (diff) | |
| parent | 4958524c32a10529604d74edd741891aeaa5c096 (diff) | |
Merge branch 'yn/worktree-add-no-dwim-with-b'
The DWIM logic in 'git worktree add' sometimes tried to infer a
remote-tracking branch when an explicit '-b' or '-B' option was
given to create a new branch, causing the explicit branch name to
be ignored, which has been corrected.
* yn/worktree-add-no-dwim-with-b:
worktree add: shouldn't dwim if -b or -B is given
| -rw-r--r-- | builtin/worktree.c | 3 | ||||
| -rwxr-xr-x | t/t2400-worktree-add.sh | 10 |
2 files changed, 13 insertions, 0 deletions
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; 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 && |
