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

[PATCH v2] submodule: mark submodules with update=none as inactive

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jul 1, 2021, 22:51 UTC
Message-ID
<20210701225117.909892-1-sandals@crustytoothpaste.net>
In-Reply-To
<YMvgRjwyrwyLz4SC@camp.crustytoothpaste.net>

When the user recursively clones a repository with submodules and one or more of those submodules is marked with the submodule.<name>.update=none configuration, the submodule will end up being active. This is a problem because we will have skipped cloning or checking out the submodule, and as a result, other commands, such as git reset or git checkout, will fail if they are invoked with --recurse-submodules (or when submodule.recurse is true).

This is obviously not the behavior the user wanted, so let's fix this by specifically setting the submodule as inactive in this case when we're initializing the repository. That will make us properly ignore the submodule when performing recursive operations.

We only do this when initializing a submodule, since git submodule update can update the submodule with various options despite the setting of "none" and we want those options to override it as they currently do.

Reported-by: Rose Kunkel <rose@rosekunkel.me>
Helped-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/submodule--helper.c |  6 ++++++
 t/t5601-clone.sh            | 24 ++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ae6174ab05..a3f8c45d97 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -686,6 +686,12 @@ static void init_submodule(const char *path, const char *prefix,
 
 		if (git_config_set_gently(sb.buf, upd))
 			die(_("Failed to register update mode for submodule path '%s'"), displaypath);
+
+		if (sub->update_strategy.type == SM_UPDATE_NONE) {
+			strbuf_reset(&sb);
+			strbuf_addf(&sb, "submodule.%s.active", sub->name);
+			git_config_set_gently(sb.buf, "false");
+		}
 	}
 	strbuf_release(&sb);
 	free(displaypath);
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
index c0688467e7..efe6b13be0 100755
--- a/t/t5601-clone.sh
+++ b/t/t5601-clone.sh
@@ -752,6 +752,30 @@ test_expect_success 'batch missing blob request does not inadvertently try to fe
 	git clone --filter=blob:limit=0 "file://$(pwd)/server" client
 '
 
+test_expect_success 'clone with submodule with update=none is not active' '
+	rm -rf server client &&
+
+	test_create_repo server &&
+	echo a >server/a &&
+	echo b >server/b &&
+	git -C server add a b &&
+	git -C server commit -m x &&
+
+	echo aa >server/a &&
+	echo bb >server/b &&
+	git -C server submodule add --name c "$(pwd)/repo_for_submodule" c &&
+	git -C server config -f .gitmodules submodule.c.update none &&
+	git -C server add a b c .gitmodules &&
+	git -C server commit -m x &&
+
+	git clone --recurse-submodules server client &&
+	git -C client config submodule.c.active >actual &&
+	echo false >expected &&
+	test_cmp actual expected &&
+	# This would fail if the submodule were active, since it is not checked out.
+	git -C client reset --recurse-submodules --hard
+'
+
 . "$TEST_DIRECTORY"/lib-httpd.sh
 start_httpd
 
Previous: Philippe BlainNext: Philippe Blain
Message 16 of 18 in “[BUG] `git reset --hard` fails with `update = none` submodules”
  1. Rose KunkelJun 16, 2021
  2. brian m. carlsonJun 16, 2021
  3. Rose KunkelJun 16, 2021
  4. Rose KunkelJun 16, 2021
  5. Rose KunkelJun 16, 2021
  6. brian m. carlsonJun 16, 2021
  7. Rose KunkelJun 16, 2021
  8. Rose KunkelJun 16, 2021
  9. Junio C HamanoJun 16, 2021
  10. Philippe BlainJun 16, 2021
  11. brian m. carlsonJun 17, 2021
  12. submodule: mark submodules with update=none as inactivebrian m. carlson, Jun 19, 2021
  13. Philippe BlainJun 22, 2021
  14. brian m. carlsonJun 25, 2021
  15. Philippe BlainJun 26, 2021
  16. submodule: mark submodules with update=none as inactivebrian m. carlson, Jul 1, 2021
  17. Philippe BlainJul 9, 2021
  18. brian m. carlsonJul 11, 2021

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.