@matheusbsbs / matheus-bagliano / commits / 552955ed7f
Fork 0

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>

Sean Barag committed Oct 1, 2020 at 03:46 UTC 552955ed7fcbc3706f2d6192487df2fb8f3283c8
1 file changed +26 -1
builtin/clone.c
+26 -1
@@ -851,8 +851,22 @@ static int checkout(int submodule_progress)
851 return err;
852 }
853
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 +
859 static int write_one_config(const char *key, const char *value, void *data)
860 {
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 +
870 return git_config_set_multivar_gently(key,
871 value ? value : "true",
872 CONFIG_REGEX_NONE, 0);
@@ -964,6 +978,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
978 struct strvec ref_prefixes = STRVEC_INIT;
979
980 packet_trace_identity("clone");
981 +
982 + git_config(git_clone_config, NULL);
983 +
984 argc = parse_options(argc, argv, prefix, builtin_clone_options,
985 builtin_clone_usage, 0);
986
@@ -1125,9 +1142,17 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
1142 if (real_git_dir)
1143 git_dir = real_git_dir;
1144
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 + */
1149 write_config(&option_config);
1150
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);
1156
1157 if (option_bare) {
1158 if (option_mirror)