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

[PATCH 4/7] submodule sync: omit setting submodule URL in config if possible

From
Stefan Beller <sbeller@google.com>
Date
Aug 16, 2018, 02:30 UTC
Message-ID
<20180816023100.161626-5-sbeller@google.com>
In-Reply-To
<20180816023100.161626-1-sbeller@google.com>

We do not need to update the submodule url in the superprojects config if the url is not used to keep the submodule active.

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/submodule--helper.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 2f20bd4abdc..639d0bb20a1 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -922,8 +922,10 @@ static void sync_submodule(const char *path, const char *prefix,
 	struct strbuf sb = STRBUF_INIT;
 	struct child_process cp = CHILD_PROCESS_INIT;
 	char *sub_config_path = NULL;
+	int active, r;
 
-	if (!is_submodule_active(the_repository, path))
+	active = is_submodule_active(the_repository, path);
+	if (!active)
 		return;
 
 	sub = submodule_from_path(the_repository, &null_oid, path);
@@ -983,13 +985,15 @@ static void sync_submodule(const char *path, const char *prefix,
 	strbuf_strip_suffix(&sb, "\n");
 	remote_key = xstrfmt("remote.%s.url", sb.buf);
 
+	if (active == SUBMODULE_ACTIVE_VIA_URL)
+		FREE_AND_NULL(sub_origin_url);
 	strbuf_reset(&sb);
 	submodule_to_gitdir(&sb, path);
 	strbuf_addstr(&sb, "/config");
-
-	if (git_config_set_in_file_gently(sb.buf, remote_key, sub_origin_url))
-		die(_("failed to update remote for submodule '%s'"),
-		      path);
+	if ((r = git_config_set_in_file_gently(sb.buf, remote_key, sub_origin_url)))
+		if (sub_origin_url || r != CONFIG_NOTHING_SET)
+			die(_("failed to update remote for submodule '%s'"),
+			      path);
 
 	if (flags & OPT_RECURSIVE) {
 		struct child_process cpr = CHILD_PROCESS_INIT;
-- 
2.18.0.265.g16de1b435c9.dirty
Previous: Junio C HamanoNext: Stefan Beller
Message 9 of 14 in “Unset the submodule URL in the superproject when no longer needed”
  1. 0/7 Unset the submodule URL in the superproject when no longer neededStefan Beller, Aug 16, 2018
  2. 1/7 t7410: update to new styleStefan Beller, Aug 16, 2018
  3. Junio C HamanoAug 16, 2018
  4. 2/7 builtin/submodule--helper: remove stray new lineStefan Beller, Aug 16, 2018
  5. 3/7 submodule: is_submodule_active to differentiate between new and old modeStefan Beller, Aug 16, 2018
  6. Junio C HamanoAug 16, 2018
  7. Stefan BellerAug 20, 2018
  8. Junio C HamanoAug 21, 2018
  9. 4/7 submodule sync: omit setting submodule URL in config if possibleStefan Beller, Aug 16, 2018
  10. 5/7 submodule--helper: factor out allocation of callback cookieStefan Beller, Aug 16, 2018
  11. 6/7 submodule--helper, update_clone: store index to update_clone instead of ceStefan Beller, Aug 16, 2018
  12. 7/7 builtin/submodule--helper: unset submodule url if possibleStefan Beller, Aug 16, 2018
  13. Junio C HamanoAug 16, 2018
  14. Stefan BellerAug 16, 2018

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.