Skip to content

Commit 4782cf2

Browse files
phil-blaingitster
authored andcommitted
worktree: teach "add" to ignore submodule.recurse config
"worktree add" internally calls "reset --hard", but if submodule.recurse is set, reset tries to recurse into initialized submodules, which makes start_command try to cd into non-existing submodule paths and die. Fix that by making sure that the call to reset in "worktree add" does not recurse. Signed-off-by: Philippe Blain <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5fa0f52 commit 4782cf2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static int add_worktree(const char *path, const char *refname,
377377
if (opts->checkout) {
378378
cp.argv = NULL;
379379
argv_array_clear(&cp.args);
380-
argv_array_pushl(&cp.args, "reset", "--hard", NULL);
380+
argv_array_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL);
381381
if (opts->quiet)
382382
argv_array_push(&cp.args, "--quiet");
383383
cp.env = child_env.argv;

t/t2400-worktree-add.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,4 +587,28 @@ test_expect_success '"add" should not fail because of another bad worktree' '
587587
)
588588
'
589589

590+
test_expect_success '"add" with uninitialized submodule, with submodule.recurse unset' '
591+
test_create_repo submodule &&
592+
test_commit -C submodule first &&
593+
test_create_repo project &&
594+
git -C project submodule add ../submodule &&
595+
git -C project add submodule &&
596+
test_tick &&
597+
git -C project commit -m add_sub &&
598+
git clone project project-clone &&
599+
git -C project-clone worktree add ../project-2
600+
'
601+
test_expect_success '"add" with uninitialized submodule, with submodule.recurse set' '
602+
git -C project-clone -c submodule.recurse worktree add ../project-3
603+
'
604+
605+
test_expect_success '"add" with initialized submodule, with submodule.recurse unset' '
606+
git -C project-clone submodule update --init &&
607+
git -C project-clone worktree add ../project-4
608+
'
609+
610+
test_expect_success '"add" with initialized submodule, with submodule.recurse set' '
611+
git -C project-clone -c submodule.recurse worktree add ../project-5
612+
'
613+
590614
test_done

0 commit comments

Comments
 (0)