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

[PATCH 5/5] submodule: use prepare_submodule_repo_env consistently

From
Jeff King <peff@peff.net>
Date
Apr 28, 2016, 13:39 UTC
Message-ID
<20160428133914.GE25319@sigill.intra.peff.net>
In-Reply-To
<20160428133534.GA19056@sigill.intra.peff.net>

Before 14111fc (git: submodule honor -c credential.* from command line, 2016-02-29), it was sufficient for code which spawned a process in a submodule to just set the child process's "env" field to "local_repo_env" to clear the environment of any repo-specific variables.

That commit introduced a more complicated procedure, in which we clear most variables but allow through sanitized config. For C code, we used that procedure only for cloning, but not for any of the programs spawned by submodule.c. As a result, things like "git fetch --recurse-submodules" behave differently than "git clone --recursive"; the former will not pass through the sanitized config.

We can fix this by using prepare_submodule_repo_env() everywhere in submodule.c.

Signed-off-by: Jeff King <peff@peff.net>
---
 submodule.c                | 14 +++++++-------
 t/t5550-http-fetch-dumb.sh | 11 +++++++++++
 2 files changed, 18 insertions(+), 7 deletions(-)
diff --git a/submodule.c b/submodule.c
index 02eaf0e..4e76b98 100644
--- a/submodule.c
+++ b/submodule.c
@@ -394,7 +394,7 @@ static int submodule_needs_pushing(const char *path, const unsigned char sha1[20
 
 		argv[1] = sha1_to_hex(sha1);
 		cp.argv = argv;
-		cp.env = local_repo_env;
+		prepare_submodule_repo_env(&cp.env_array);
 		cp.git_cmd = 1;
 		cp.no_stdin = 1;
 		cp.out = -1;
@@ -481,7 +481,7 @@ static int push_submodule(const char *path)
 		const char *argv[] = {"push", NULL};
 
 		cp.argv = argv;
-		cp.env = local_repo_env;
+		prepare_submodule_repo_env(&cp.env_array);
 		cp.git_cmd = 1;
 		cp.no_stdin = 1;
 		cp.dir = path;
@@ -527,7 +527,7 @@ static int is_submodule_commit_present(const char *path, unsigned char sha1[20])
 
 		argv[3] = sha1_to_hex(sha1);
 		cp.argv = argv;
-		cp.env = local_repo_env;
+		prepare_submodule_repo_env(&cp.env_array);
 		cp.git_cmd = 1;
 		cp.no_stdin = 1;
 		cp.dir = path;
@@ -710,7 +710,7 @@ static int get_next_submodule(struct child_process *cp,
 		if (is_directory(git_dir)) {
 			child_process_init(cp);
 			cp->dir = strbuf_detach(&submodule_path, NULL);
-			cp->env = local_repo_env;
+			prepare_submodule_repo_env(&cp->env_array);
 			cp->git_cmd = 1;
 			if (!spf->quiet)
 				strbuf_addf(err, "Fetching submodule %s%s\n",
@@ -825,7 +825,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
 		argv[2] = "-uno";
 
 	cp.argv = argv;
-	cp.env = local_repo_env;
+	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
 	cp.no_stdin = 1;
 	cp.out = -1;
@@ -886,7 +886,7 @@ int submodule_uses_gitfile(const char *path)
 
 	/* Now test that all nested submodules use a gitfile too */
 	cp.argv = argv;
-	cp.env = local_repo_env;
+	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
 	cp.no_stdin = 1;
 	cp.no_stderr = 1;
@@ -919,7 +919,7 @@ int ok_to_remove_submodule(const char *path)
 		return 0;
 
 	cp.argv = argv;
-	cp.env = local_repo_env;
+	prepare_submodule_repo_env(&cp.env_array);
 	cp.git_cmd = 1;
 	cp.no_stdin = 1;
 	cp.out = -1;
diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh
index 13ac788..3484b6f 100755
--- a/t/t5550-http-fetch-dumb.sh
+++ b/t/t5550-http-fetch-dumb.sh
@@ -112,6 +112,17 @@ test_expect_success 'cmdline credential config passes to submodule via clone' '
 	expect_askpass pass user@host
 '
 
+test_expect_success 'cmdline credential config passes submodule via fetch' '
+	set_askpass wrong pass@host &&
+	test_must_fail git -C super-clone fetch --recurse-submodules &&
+
+	set_askpass wrong pass@host &&
+	git -C super-clone \
+	    -c "credential.$HTTPD_URL.username=user@host" \
+	    fetch --recurse-submodules &&
+	expect_askpass pass user@host
+'
+
 test_expect_success 'cmdline credential config passes submodule update' '
 	# advance the submodule HEAD so that a fetch is required
 	git commit --allow-empty -m foo &&
-- 
2.8.1.617.gbdccc2d
Previous: Lars SchneiderNext: Johannes Schindelin
Message 31 of 36 in “[RFC] How to pass Git config command line instructions to Submodule commands?”
  1. Lars SchneiderApr 25, 2016
  2. Stefan BellerApr 25, 2016
  3. Jacob KellerApr 25, 2016
  4. Jeff KingApr 25, 2016
  5. Jeff KingApr 25, 2016
  6. Lars SchneiderApr 28, 2016
  7. Jeff KingApr 28, 2016
  8. Jeff KingApr 28, 2016
  9. Jeff KingApr 28, 2016
  10. 0/5 fixes for sanitized submodule configJeff King, Apr 28, 2016
  11. 1/5 t5550: fix typo in $HTTPD_URLJeff King, Apr 28, 2016
  12. Jacob KellerApr 28, 2016
  13. Jeff KingApr 28, 2016
  14. Jacob KellerApr 28, 2016
  15. 2/5 t5550: break submodule config test into multiple sub-testsJeff King, Apr 28, 2016
  16. Stefan BellerApr 28, 2016
  17. Jeff KingApr 28, 2016
  18. Jacob KellerApr 28, 2016
  19. 3/5 submodule: export sanitized GIT_CONFIG_PARAMETERSJeff King, Apr 28, 2016
  20. Stefan BellerApr 28, 2016
  21. Jeff KingApr 28, 2016
  22. Stefan BellerApr 28, 2016
  23. Johannes SchindelinApr 28, 2016
  24. Jacob KellerApr 28, 2016
  25. Jeff KingApr 28, 2016
  26. Jacob KellerApr 28, 2016
  27. 4/5 submodule--helper: move config-sanitizing to submodule.cJeff King, Apr 28, 2016
  28. Stefan BellerApr 28, 2016
  29. Jeff KingApr 28, 2016
  30. Lars SchneiderApr 28, 2016
  31. 5/5 submodule: use prepare_submodule_repo_env consistentlyJeff King, Apr 28, 2016
  32. Johannes SchindelinApr 28, 2016
  33. Stefan BellerApr 28, 2016
  34. Jacob KellerApr 28, 2016
  35. Lars SchneiderApr 28, 2016
  36. Jeff KingApr 28, 2016

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.