]> git.ipfire.org Git - thirdparty/git.git/commitdiff
worktree: teach "add" to ignore submodule.recurse config
authorPhilippe Blain <levraiphilippeblain@gmail.com>
Sun, 27 Oct 2019 17:16:25 +0000 (17:16 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 30 Oct 2019 00:57:15 +0000 (09:57 +0900)
"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>
builtin/worktree.c
t/t2400-worktree-add.sh

index a5bb02b2076a27a78947fda25c1e16dafd637622..958bea97fe17e36727650eeff5703bd520528477 100644 (file)
@@ -377,7 +377,7 @@ static int add_worktree(const char *path, const char *refname,
        if (opts->checkout) {
                cp.argv = NULL;
                argv_array_clear(&cp.args);
-               argv_array_pushl(&cp.args, "reset", "--hard", NULL);
+               argv_array_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL);
                if (opts->quiet)
                        argv_array_push(&cp.args, "--quiet");
                cp.env = child_env.argv;
index e819ba741ec96018755a08ef956998edfdd1dcc4..8a9831413c38e69ce121497e112042cf3d436748 100755 (executable)
@@ -587,4 +587,28 @@ test_expect_success '"add" should not fail because of another bad worktree' '
        )
 '
 
+test_expect_success '"add" with uninitialized submodule, with submodule.recurse unset' '
+       test_create_repo submodule &&
+       test_commit -C submodule first &&
+       test_create_repo project &&
+       git -C project submodule add ../submodule &&
+       git -C project add submodule &&
+       test_tick &&
+       git -C project commit -m add_sub &&
+       git clone project project-clone &&
+       git -C project-clone worktree add ../project-2
+'
+test_expect_success '"add" with uninitialized submodule, with submodule.recurse set' '
+       git -C project-clone -c submodule.recurse worktree add ../project-3
+'
+
+test_expect_success '"add" with initialized submodule, with submodule.recurse unset' '
+       git -C project-clone submodule update --init &&
+       git -C project-clone worktree add ../project-4
+'
+
+test_expect_success '"add" with initialized submodule, with submodule.recurse set' '
+       git -C project-clone -c submodule.recurse worktree add ../project-5
+'
+
 test_done