Skip to content

Commit feaf144

Browse files
peffdscho
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 79aec59 commit feaf144

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

submodule.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static int submodule_needs_pushing(const char *path, const unsigned char sha1[20
367367

368368
argv[1] = sha1_to_hex(sha1);
369369
cp.argv = argv;
370-
cp.env = local_repo_env;
370+
prepare_submodule_repo_env(&cp.env_array);
371371
cp.git_cmd = 1;
372372
cp.no_stdin = 1;
373373
cp.out = -1;
@@ -454,7 +454,7 @@ static int push_submodule(const char *path)
454454
const char *argv[] = {"push", NULL};
455455

456456
cp.argv = argv;
457-
cp.env = local_repo_env;
457+
prepare_submodule_repo_env(&cp.env_array);
458458
cp.git_cmd = 1;
459459
cp.no_stdin = 1;
460460
cp.dir = path;
@@ -500,7 +500,7 @@ static int is_submodule_commit_present(const char *path, unsigned char sha1[20])
500500

501501
argv[3] = sha1_to_hex(sha1);
502502
cp.argv = argv;
503-
cp.env = local_repo_env;
503+
prepare_submodule_repo_env(&cp.env_array);
504504
cp.git_cmd = 1;
505505
cp.no_stdin = 1;
506506
cp.dir = path;
@@ -683,7 +683,7 @@ static int get_next_submodule(struct child_process *cp,
683683
if (is_directory(git_dir)) {
684684
child_process_init(cp);
685685
cp->dir = strbuf_detach(&submodule_path, NULL);
686-
cp->env = local_repo_env;
686+
prepare_submodule_repo_env(&cp->env_array);
687687
cp->git_cmd = 1;
688688
if (!spf->quiet)
689689
strbuf_addf(err, "Fetching submodule %s%s\n",
@@ -795,7 +795,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
795795
argv[2] = "-uno";
796796

797797
cp.argv = argv;
798-
cp.env = local_repo_env;
798+
prepare_submodule_repo_env(&cp.env_array);
799799
cp.git_cmd = 1;
800800
cp.no_stdin = 1;
801801
cp.out = -1;
@@ -856,7 +856,7 @@ int submodule_uses_gitfile(const char *path)
856856

857857
/* Now test that all nested submodules use a gitfile too */
858858
cp.argv = argv;
859-
cp.env = local_repo_env;
859+
prepare_submodule_repo_env(&cp.env_array);
860860
cp.git_cmd = 1;
861861
cp.no_stdin = 1;
862862
cp.no_stderr = 1;
@@ -889,7 +889,7 @@ int ok_to_remove_submodule(const char *path)
889889
return 0;
890890

891891
cp.argv = argv;
892-
cp.env = local_repo_env;
892+
prepare_submodule_repo_env(&cp.env_array);
893893
cp.git_cmd = 1;
894894
cp.no_stdin = 1;
895895
cp.out = -1;

t/t5550-http-fetch-dumb.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ test_expect_success 'cmdline credential config passes to submodule via clone' '
112112
expect_askpass pass user@host
113113
'
114114

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+
115126
test_expect_success 'cmdline credential config passes submodule update' '
116127
# advance the submodule HEAD so that a fetch is required
117128
git commit --allow-empty -m foo &&

0 commit comments

Comments
 (0)