Merge branch 'jk/submodule-c-credential'
"git -c credential.<var>=<value> submodule" can now be used to propagate configuration variables related to credential helper down to the submodules. * jk/submodule-c-credential: git_config_push_parameter: handle empty GIT_CONFIG_PARAMETERS git: submodule honor -c credential.* from command line quote: implement sq_quotef() submodule: fix segmentation fault in submodule--helper clone submodule: fix submodule--helper clone usage submodule: check argc count for git submodule--helper clone submodule: don't pass empty string arguments to submodule--helper clone
This commit is contained in:
@ -118,6 +118,55 @@ static int module_name(int argc, const char **argv, const char *prefix)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Rules to sanitize configuration variables that are Ok to be passed into
|
||||
* submodule operations from the parent project using "-c". Should only
|
||||
* include keys which are both (a) safe and (b) necessary for proper
|
||||
* operation.
|
||||
*/
|
||||
static int submodule_config_ok(const char *var)
|
||||
{
|
||||
if (starts_with(var, "credential."))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sanitize_submodule_config(const char *var, const char *value, void *data)
|
||||
{
|
||||
struct strbuf *out = data;
|
||||
|
||||
if (submodule_config_ok(var)) {
|
||||
if (out->len)
|
||||
strbuf_addch(out, ' ');
|
||||
|
||||
if (value)
|
||||
sq_quotef(out, "%s=%s", var, value);
|
||||
else
|
||||
sq_quote_buf(out, var);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void prepare_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)
|
||||
{
|
||||
@ -139,7 +188,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;
|
||||
prepare_submodule_repo_env(&cp.env_array);
|
||||
cp.no_stdin = 1;
|
||||
|
||||
return run_command(&cp);
|
||||
@ -180,14 +229,18 @@ static int module_clone(int argc, const char **argv, const char *prefix)
|
||||
|
||||
const char *const git_submodule_helper_usage[] = {
|
||||
N_("git submodule--helper clone [--prefix=<path>] [--quiet] "
|
||||
"[--reference <repository>] [--name <name>] [--url <url>]"
|
||||
"[--depth <depth>] [--] [<path>...]"),
|
||||
"[--reference <repository>] [--name <name>] [--depth <depth>] "
|
||||
"--url <url> --path <path>"),
|
||||
NULL
|
||||
};
|
||||
|
||||
argc = parse_options(argc, argv, prefix, module_clone_options,
|
||||
git_submodule_helper_usage, 0);
|
||||
|
||||
if (argc || !url || !path)
|
||||
usage_with_options(git_submodule_helper_usage,
|
||||
module_clone_options);
|
||||
|
||||
strbuf_addf(&sb, "%s/modules/%s", get_git_dir(), name);
|
||||
sm_gitdir = strbuf_detach(&sb, NULL);
|
||||
|
||||
@ -249,6 +302,22 @@ static int module_clone(int argc, const char **argv, const char *prefix)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int module_sanitize_config(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
struct strbuf sanitized_config = STRBUF_INIT;
|
||||
|
||||
if (argc > 1)
|
||||
usage(_("git submodule--helper sanitize-config"));
|
||||
|
||||
git_config_from_parameters(sanitize_submodule_config, &sanitized_config);
|
||||
if (sanitized_config.len)
|
||||
printf("%s\n", sanitized_config.buf);
|
||||
|
||||
strbuf_release(&sanitized_config);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct submodule_update_clone {
|
||||
/* index into 'list', the list of submodules to look into for cloning */
|
||||
int current;
|
||||
@ -509,6 +578,7 @@ static struct cmd_struct commands[] = {
|
||||
{"list", module_list},
|
||||
{"name", module_name},
|
||||
{"clone", module_clone},
|
||||
{"sanitize-config", module_sanitize_config},
|
||||
{"update-clone", update_clone}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user