Skip to content

Commit e059388

Browse files
committed
Merge branch 'jk/submodule-c-credential'
An earlier addition of "sanitize_submodule_env" with 14111fc (git: submodule honor -c credential.* from command line, 2016-02-29) turned out to be a convoluted no-op; implement what it wanted to do correctly, and stop filtering settings given via "git -c var=val". * jk/submodule-c-credential: submodule: stop sanitizing config options submodule: use prepare_submodule_repo_env consistently submodule--helper: move config-sanitizing to submodule.c submodule: export sanitized GIT_CONFIG_PARAMETERS t5550: break submodule config test into multiple sub-tests t5550: fix typo in $HTTPD_URL
2 parents 7a7d085 + 89044ba commit e059388

File tree

6 files changed

+63
-103
lines changed

6 files changed

+63
-103
lines changed

builtin/submodule--helper.c

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -443,54 +443,6 @@ static int module_name(int argc, const char **argv, const char *prefix)
443443
return 0;
444444
}
445445

446-
/*
447-
* Rules to sanitize configuration variables that are Ok to be passed into
448-
* submodule operations from the parent project using "-c". Should only
449-
* include keys which are both (a) safe and (b) necessary for proper
450-
* operation.
451-
*/
452-
static int submodule_config_ok(const char *var)
453-
{
454-
if (starts_with(var, "credential."))
455-
return 1;
456-
return 0;
457-
}
458-
459-
static int sanitize_submodule_config(const char *var, const char *value, void *data)
460-
{
461-
struct strbuf *out = data;
462-
463-
if (submodule_config_ok(var)) {
464-
if (out->len)
465-
strbuf_addch(out, ' ');
466-
467-
if (value)
468-
sq_quotef(out, "%s=%s", var, value);
469-
else
470-
sq_quote_buf(out, var);
471-
}
472-
473-
return 0;
474-
}
475-
476-
static void prepare_submodule_repo_env(struct argv_array *out)
477-
{
478-
const char * const *var;
479-
480-
for (var = local_repo_env; *var; var++) {
481-
if (!strcmp(*var, CONFIG_DATA_ENVIRONMENT)) {
482-
struct strbuf sanitized_config = STRBUF_INIT;
483-
git_config_from_parameters(sanitize_submodule_config,
484-
&sanitized_config);
485-
argv_array_pushf(out, "%s=%s", *var, sanitized_config.buf);
486-
strbuf_release(&sanitized_config);
487-
} else {
488-
argv_array_push(out, *var);
489-
}
490-
}
491-
492-
}
493-
494446
static int clone_submodule(const char *path, const char *gitdir, const char *url,
495447
const char *depth, const char *reference, int quiet)
496448
{
@@ -618,22 +570,6 @@ static int module_clone(int argc, const char **argv, const char *prefix)
618570
return 0;
619571
}
620572

621-
static int module_sanitize_config(int argc, const char **argv, const char *prefix)
622-
{
623-
struct strbuf sanitized_config = STRBUF_INIT;
624-
625-
if (argc > 1)
626-
usage(_("git submodule--helper sanitize-config"));
627-
628-
git_config_from_parameters(sanitize_submodule_config, &sanitized_config);
629-
if (sanitized_config.len)
630-
printf("%s\n", sanitized_config.buf);
631-
632-
strbuf_release(&sanitized_config);
633-
634-
return 0;
635-
}
636-
637573
struct submodule_update_clone {
638574
/* index into 'list', the list of submodules to look into for cloning */
639575
int current;
@@ -906,7 +842,6 @@ static struct cmd_struct commands[] = {
906842
{"list", module_list},
907843
{"name", module_name},
908844
{"clone", module_clone},
909-
{"sanitize-config", module_sanitize_config},
910845
{"update-clone", update_clone},
911846
{"resolve-relative-url", resolve_relative_url},
912847
{"resolve-relative-url-test", resolve_relative_url_test},

git-submodule.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ isnumber()
124124
# of the settings from GIT_CONFIG_PARAMETERS.
125125
sanitize_submodule_env()
126126
{
127-
sanitized_config=$(git submodule--helper sanitize-config)
127+
save_config=$GIT_CONFIG_PARAMETERS
128128
clear_local_git_env
129-
GIT_CONFIG_PARAMETERS=$sanitized_config
129+
GIT_CONFIG_PARAMETERS=$save_config
130+
export GIT_CONFIG_PARAMETERS
130131
}
131132

132133
#

submodule.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "argv-array.h"
1414
#include "blob.h"
1515
#include "thread-utils.h"
16+
#include "quote.h"
1617

1718
static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
1819
static int parallel_jobs = 1;
@@ -414,7 +415,7 @@ static int submodule_needs_pushing(const char *path, const unsigned char sha1[20
414415

415416
argv[1] = sha1_to_hex(sha1);
416417
cp.argv = argv;
417-
cp.env = local_repo_env;
418+
prepare_submodule_repo_env(&cp.env_array);
418419
cp.git_cmd = 1;
419420
cp.no_stdin = 1;
420421
cp.out = -1;
@@ -501,7 +502,7 @@ static int push_submodule(const char *path)
501502
const char *argv[] = {"push", NULL};
502503

503504
cp.argv = argv;
504-
cp.env = local_repo_env;
505+
prepare_submodule_repo_env(&cp.env_array);
505506
cp.git_cmd = 1;
506507
cp.no_stdin = 1;
507508
cp.dir = path;
@@ -547,7 +548,7 @@ static int is_submodule_commit_present(const char *path, unsigned char sha1[20])
547548

548549
argv[3] = sha1_to_hex(sha1);
549550
cp.argv = argv;
550-
cp.env = local_repo_env;
551+
prepare_submodule_repo_env(&cp.env_array);
551552
cp.git_cmd = 1;
552553
cp.no_stdin = 1;
553554
cp.dir = path;
@@ -730,7 +731,7 @@ static int get_next_submodule(struct child_process *cp,
730731
if (is_directory(git_dir)) {
731732
child_process_init(cp);
732733
cp->dir = strbuf_detach(&submodule_path, NULL);
733-
cp->env = local_repo_env;
734+
prepare_submodule_repo_env(&cp->env_array);
734735
cp->git_cmd = 1;
735736
if (!spf->quiet)
736737
strbuf_addf(err, "Fetching submodule %s%s\n",
@@ -845,7 +846,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
845846
argv[2] = "-uno";
846847

847848
cp.argv = argv;
848-
cp.env = local_repo_env;
849+
prepare_submodule_repo_env(&cp.env_array);
849850
cp.git_cmd = 1;
850851
cp.no_stdin = 1;
851852
cp.out = -1;
@@ -906,7 +907,7 @@ int submodule_uses_gitfile(const char *path)
906907

907908
/* Now test that all nested submodules use a gitfile too */
908909
cp.argv = argv;
909-
cp.env = local_repo_env;
910+
prepare_submodule_repo_env(&cp.env_array);
910911
cp.git_cmd = 1;
911912
cp.no_stdin = 1;
912913
cp.no_stderr = 1;
@@ -939,7 +940,7 @@ int ok_to_remove_submodule(const char *path)
939940
return 0;
940941

941942
cp.argv = argv;
942-
cp.env = local_repo_env;
943+
prepare_submodule_repo_env(&cp.env_array);
943944
cp.git_cmd = 1;
944945
cp.no_stdin = 1;
945946
cp.out = -1;
@@ -1150,3 +1151,13 @@ int parallel_submodules(void)
11501151
{
11511152
return parallel_jobs;
11521153
}
1154+
1155+
void prepare_submodule_repo_env(struct argv_array *out)
1156+
{
1157+
const char * const *var;
1158+
1159+
for (var = local_repo_env; *var; var++) {
1160+
if (strcmp(*var, CONFIG_DATA_ENVIRONMENT))
1161+
argv_array_push(out, *var);
1162+
}
1163+
}

submodule.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,11 @@ int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_nam
6262
void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
6363
int parallel_submodules(void);
6464

65+
/*
66+
* Prepare the "env_array" parameter of a "struct child_process" for executing
67+
* a submodule by clearing any repo-specific envirionment variables, but
68+
* retaining any config in the environment.
69+
*/
70+
void prepare_submodule_repo_env(struct argv_array *out);
71+
6572
#endif

t/t5550-http-fetch-dumb.sh

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,55 @@ test_expect_success 'configured username does not override URL' '
9191
expect_askpass pass user@host
9292
'
9393

94-
test_expect_success 'cmdline credential config passes into submodules' '
94+
test_expect_success 'set up repo with http submodules' '
9595
git init super &&
9696
set_askpass user@host pass@host &&
9797
(
9898
cd super &&
9999
git submodule add "$HTTPD_URL/auth/dumb/repo.git" sub &&
100100
git commit -m "add submodule"
101-
) &&
101+
)
102+
'
103+
104+
test_expect_success 'cmdline credential config passes to submodule via clone' '
102105
set_askpass wrong pass@host &&
103106
test_must_fail git clone --recursive super super-clone &&
104107
rm -rf super-clone &&
108+
105109
set_askpass wrong pass@host &&
106-
git -c "credential.$HTTP_URL.username=user@host" \
110+
git -c "credential.$HTTPD_URL.username=user@host" \
107111
clone --recursive super super-clone &&
108112
expect_askpass pass user@host
109113
'
110114

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 &&
129+
git push "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git" HEAD &&
130+
sha1=$(git rev-parse HEAD) &&
131+
git -C super-clone update-index --cacheinfo 160000,$sha1,sub &&
132+
133+
set_askpass wrong pass@host &&
134+
test_must_fail git -C super-clone submodule update &&
135+
136+
set_askpass wrong pass@host &&
137+
git -C super-clone \
138+
-c "credential.$HTTPD_URL.username=user@host" \
139+
submodule update &&
140+
expect_askpass pass user@host
141+
'
142+
111143
test_expect_success 'fetch changes via http' '
112144
echo content >>file &&
113145
git commit -a -m two &&

t/t7412-submodule--helper.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)