submodule: use prepare_submodule_repo_env consistently

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Apr 28, 2016 at 09:39 UTC c12e8656700be6084aec49df66447e701fda1ecf
2 files changed +18 -7
submodule.c
+7 -7
@@ -367,7 +367,7 @@ static int submodule_needs_pushing(const char *path, const unsigned char sha1[20
367
368 argv[1] = sha1_to_hex(sha1);
369 cp.argv = argv;
370 - cp.env = local_repo_env;
370 + prepare_submodule_repo_env(&cp.env_array);
371 cp.git_cmd = 1;
372 cp.no_stdin = 1;
373 cp.out = -1;
@@ -454,7 +454,7 @@ static int push_submodule(const char *path)
454 const char *argv[] = {"push", NULL};
455
456 cp.argv = argv;
457 - cp.env = local_repo_env;
457 + prepare_submodule_repo_env(&cp.env_array);
458 cp.git_cmd = 1;
459 cp.no_stdin = 1;
460 cp.dir = path;
@@ -500,7 +500,7 @@ static int is_submodule_commit_present(const char *path, unsigned char sha1[20])
500
501 argv[3] = sha1_to_hex(sha1);
502 cp.argv = argv;
503 - cp.env = local_repo_env;
503 + prepare_submodule_repo_env(&cp.env_array);
504 cp.git_cmd = 1;
505 cp.no_stdin = 1;
506 cp.dir = path;
@@ -683,7 +683,7 @@ static int get_next_submodule(struct child_process *cp,
683 if (is_directory(git_dir)) {
684 child_process_init(cp);
685 cp->dir = strbuf_detach(&submodule_path, NULL);
686 - cp->env = local_repo_env;
686 + prepare_submodule_repo_env(&cp->env_array);
687 cp->git_cmd = 1;
688 if (!spf->quiet)
689 strbuf_addf(err, "Fetching submodule %s%s\n",
@@ -796,7 +796,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
796 argv[2] = "-uno";
797
798 cp.argv = argv;
799 - cp.env = local_repo_env;
799 + prepare_submodule_repo_env(&cp.env_array);
800 cp.git_cmd = 1;
801 cp.no_stdin = 1;
802 cp.out = -1;
@@ -857,7 +857,7 @@ int submodule_uses_gitfile(const char *path)
857
858 /* Now test that all nested submodules use a gitfile too */
859 cp.argv = argv;
860 - cp.env = local_repo_env;
860 + prepare_submodule_repo_env(&cp.env_array);
861 cp.git_cmd = 1;
862 cp.no_stdin = 1;
863 cp.no_stderr = 1;
@@ -890,7 +890,7 @@ int ok_to_remove_submodule(const char *path)
890 return 0;
891
892 cp.argv = argv;
893 - cp.env = local_repo_env;
893 + prepare_submodule_repo_env(&cp.env_array);
894 cp.git_cmd = 1;
895 cp.no_stdin = 1;
896 cp.out = -1;
t/t5550-http-fetch-dumb.sh
+11
@@ -112,6 +112,17 @@ test_expect_success 'cmdline credential config passes to submodule via clone' '
112 expect_askpass pass user@host
113 '
114
115 +test_expect_success 'cmdline credential config passes submodule via fetch' '
116 + set_askpass wrong pass@host &&
117 + test_must_fail git -C super-clone fetch --recurse-submodules &&
118 +
119 + set_askpass wrong pass@host &&
120 + git -C super-clone \
121 + -c "credential.$HTTPD_URL.username=user@host" \
122 + fetch --recurse-submodules &&
123 + expect_askpass pass user@host
124 +'
125 +
126 test_expect_success 'cmdline credential config passes submodule update' '
127 # advance the submodule HEAD so that a fetch is required
128 git commit --allow-empty -m foo &&