summaryrefslogtreecommitdiff
path: root/builtin/clone.c
diff options
context:
space:
mode:
authorLibravatar Sean Barag <sean@barag.org>2020-10-01 03:46:11 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2020-09-30 22:09:13 -0700
commit552955ed7fcbc3706f2d6192487df2fb8f3283c8 (patch)
tree775bf086ecec972a7e7b632d61fb01d24ab62b7c /builtin/clone.c
parentclone: add tests for --template and some disallowed option pairs (diff)
downloadtgif-552955ed7fcbc3706f2d6192487df2fb8f3283c8.tar.xz
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 <gitster@pobox.com> Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Sean Barag <sean@barag.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/clone.c')
-rw-r--r--builtin/clone.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/builtin/clone.c b/builtin/clone.c
index b087ee40c2..258bfd65b7 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -851,8 +851,22 @@ static int checkout(int submodule_progress)
return err;
}
+static int git_clone_config(const char *k, const char *v, void *cb)
+{
+ return git_default_config(k, v, cb);
+}
+
static int write_one_config(const char *key, const char *value, void *data)
{
+ /*
+ * give git_clone_config a chance to write config values back to the
+ * environment, since git_config_set_multivar_gently only deals with
+ * config-file writes
+ */
+ int apply_failed = git_clone_config(key, value, data);
+ if (apply_failed)
+ return apply_failed;
+
return git_config_set_multivar_gently(key,
value ? value : "true",
CONFIG_REGEX_NONE, 0);
@@ -964,6 +978,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
struct strvec ref_prefixes = STRVEC_INIT;
packet_trace_identity("clone");
+
+ git_config(git_clone_config, NULL);
+
argc = parse_options(argc, argv, prefix, builtin_clone_options,
builtin_clone_usage, 0);
@@ -1125,9 +1142,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (real_git_dir)
git_dir = real_git_dir;
+ /*
+ * additional config can be injected with -c, make sure it's included
+ * after init_db, which clears the entire config environment.
+ */
write_config(&option_config);
- git_config(git_default_config, NULL);
+ /*
+ * re-read config after init_db and write_config to pick up any config
+ * injected by --template and --config, respectively.
+ */
+ git_config(git_clone_config, NULL);
if (option_bare) {
if (option_mirror)