mirror of
https://github.com/git/git.git
synced 2026-08-08 17:11:48 +00:00
worktree add: shouldn't dwim if -b or -B is given
'git worktree add <path> <branch>' DWIMs <branch> to a
remote-tracking branch when neither -b, -B, nor --detach
is given.
However, 'git worktree add -b <new-branch> <path> <branch>' can
still DWIM <branch>, causing <new-branch> to be ignored. This is a
regression introduced by 128e5496b3 (worktree add: extend DWIM to
infer --orphan, 2023-05-17), which appeared in Git 2.42.
Signed-off-by: Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
e9019fcafe
commit
a07cc06fbe
@@ -897,16 +897,18 @@ 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) {
|
||||
struct object_id oid;
|
||||
struct commit *commit;
|
||||
char *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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
Reference in New Issue
Block a user