git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/1] worktree: teach "add" to ignore submodule.recurse config

From
Philippe Blain via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 27, 2019, 17:16 UTC
Message-ID
<e707bcc0a8482a8e8e82ecb259fa0dff84e63955.1572196585.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.430.git.1572196585.gitgitgadget@gmail.com>
From: Philippe Blain <levraiphilippeblain@gmail.com>

"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>
---
 builtin/worktree.c      |  2 +-
 t/t2400-worktree-add.sh | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/builtin/worktree.c b/builtin/worktree.c
index a5bb02b207..958bea97fe 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -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;
diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh
index e819ba741e..8a9831413c 100755
--- a/t/t2400-worktree-add.sh
+++ b/t/t2400-worktree-add.sh
@@ -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
-- 
gitgitgadget
Previous: Philippe Blain via GitGitGadgetNext: Junio C Hamano
Message 2 of 5 in “worktree: teach "add" to ignore submodule.recurse config”
  1. 0/1 worktree: teach "add" to ignore submodule.recurse configPhilippe Blain via GitGitGadget, Oct 27, 2019
  2. 1/1 worktree: teach "add" to ignore submodule.recurse configPhilippe Blain via GitGitGadget, Oct 27, 2019
  3. Junio C HamanoOct 28, 2019
  4. Philippe BlainOct 29, 2019
  5. Junio C HamanoOct 30, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.