Skip to content

Commit 552955e

Browse files
sjbaraggitster
authored andcommitted
clone: use more conventional config/option layering
Parsing command-line options before reading from config required careful handling to ensure CLI options were treated with higher priority. Read config first to let parsed CLI naively overwrite matching config values. Helped-by: Junio C Hamano <[email protected]> Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: Sean Barag <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 349cff7 commit 552955e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

builtin/clone.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,22 @@ static int checkout(int submodule_progress)
851851
return err;
852852
}
853853

854+
static int git_clone_config(const char *k, const char *v, void *cb)
855+
{
856+
return git_default_config(k, v, cb);
857+
}
858+
854859
static int write_one_config(const char *key, const char *value, void *data)
855860
{
861+
/*
862+
* give git_clone_config a chance to write config values back to the
863+
* environment, since git_config_set_multivar_gently only deals with
864+
* config-file writes
865+
*/
866+
int apply_failed = git_clone_config(key, value, data);
867+
if (apply_failed)
868+
return apply_failed;
869+
856870
return git_config_set_multivar_gently(key,
857871
value ? value : "true",
858872
CONFIG_REGEX_NONE, 0);
@@ -964,6 +978,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
964978
struct strvec ref_prefixes = STRVEC_INIT;
965979

966980
packet_trace_identity("clone");
981+
982+
git_config(git_clone_config, NULL);
983+
967984
argc = parse_options(argc, argv, prefix, builtin_clone_options,
968985
builtin_clone_usage, 0);
969986

@@ -1125,9 +1142,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11251142
if (real_git_dir)
11261143
git_dir = real_git_dir;
11271144

1145+
/*
1146+
* additional config can be injected with -c, make sure it's included
1147+
* after init_db, which clears the entire config environment.
1148+
*/
11281149
write_config(&option_config);
11291150

1130-
git_config(git_default_config, NULL);
1151+
/*
1152+
* re-read config after init_db and write_config to pick up any config
1153+
* injected by --template and --config, respectively.
1154+
*/
1155+
git_config(git_clone_config, NULL);
11311156

11321157
if (option_bare) {
11331158
if (option_mirror)

0 commit comments

Comments
 (0)