@matheusbsbs / matheus-bagliano / commits / 4782cf2ab6
Fork 0

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 <levraiphilippeblain@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Philippe Blain committed Oct 27, 2019 at 17:16 UTC 4782cf2ab686bacca8d2908319981ac27d54ca25
2 files changed +25 -1
builtin/worktree.c
+1 -1
@@ -377,7 +377,7 @@ static int add_worktree(const char *path, const char *refname,
377 if (opts->checkout) {
378 cp.argv = NULL;
379 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);
381 if (opts->quiet)
382 argv_array_push(&cp.args, "--quiet");
383 cp.env = child_env.argv;
t/t2400-worktree-add.sh
+24
@@ -587,4 +587,28 @@ test_expect_success '"add" should not fail because of another bad worktree' '
587 )
588 '
589
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 +
614 test_done