Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builtin/worktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ 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) {
} else if (ac == 2 && !new_branch) {
struct object_id oid;
struct commit *commit;
char *remote;
Expand Down
10 changes: 10 additions & 0 deletions t/t2400-worktree-add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 foo &&
setup_remote_repo repo_upstream repo_dwim &&
git init repo_dwim &&
(
cd repo_dwim &&
test_must_fail git worktree add -b branch ../foo foo
)
'

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 &&
Expand Down
Loading