Re: [PATCH v2] git: submodule honor -c credential.* from command line
flat view
From: Jeff King <hidden>
Date: 2016-06-15 23:08:26
Subsystem:
the rest · Maintainer:
Linus Torvalds
On Thu, Feb 25, 2016 at 02:00:36AM -0500, Jeff King wrote:
I think something like this would work: [...] but it does not seem to pass with your patch (even after I fixed up the weird "local" thing). I think the problem is that we ask submodule--helper to do the clone, and it uses local_repo_env. So in addition to your patch, you probably need a C version of the same thing which outputs to an argv_array.
Something like this (which passes my test, but I didn't think hard about it beyond that):
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 8b3320e..fa941fd 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c@@ -124,6 +124,27 @@ static int module_name(int argc, const char **argv, const char *prefix) return 0; } + +/* this (and submodule_config_ok) should be static in the original */ +int sanitize_submodule_config(const char *, const char *, void *); + +static void add_submodule_repo_env(struct argv_array *out) +{ + const char * const *var; + + for (var = local_repo_env; *var; var++) { + if (!strcmp(*var, CONFIG_DATA_ENVIRONMENT)) { + struct strbuf sanitized_config = STRBUF_INIT; + git_config_from_parameters(sanitize_submodule_config, + &sanitized_config); + argv_array_pushf(out, "%s=%s", *var, sanitized_config.buf); + strbuf_release(&sanitized_config); + } else { + argv_array_push(out, *var); + } + } +} + static int clone_submodule(const char *path, const char *gitdir, const char *url, const char *depth, const char *reference, int quiet) {
@@ -145,7 +166,7 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url argv_array_push(&cp.args, path); cp.git_cmd = 1; - cp.env = local_repo_env; + add_submodule_repo_env(&cp.env_array); cp.no_stdin = 1; return run_command(&cp);