submodule--helper: don't overlay config in update-clone
Don't rely on overlaying the repository's config on top of the submodule-config, instead query the repository's config directly for the url and the update strategy configuration. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Aug 3, 2017 at 11:19 UTC
ec6141a0f290ba5a0cea2d15820be0223467e656
3 files changed
+46
-16
builtin/submodule--helper.c
+19
-4
@@ -780,6 +780,10 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
780
struct strbuf *out)
781
{
782
const struct submodule *sub = NULL;
783
+ const char *url = NULL;
784
+ const char *update_string;
785
+ enum submodule_update_type update_type;
786
+ char *key;
787
struct strbuf displaypath_sb = STRBUF_INIT;
788
struct strbuf sb = STRBUF_INIT;
789
const char *displaypath = NULL;
@@ -808,9 +812,17 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
812
goto cleanup;
813
}
814
815
+ key = xstrfmt("submodule.%s.update", sub->name);
816
+ if (!repo_config_get_string_const(the_repository, key, &update_string)) {
817
+ update_type = parse_submodule_update_type(update_string);
818
+ } else {
819
+ update_type = sub->update_strategy.type;
820
+ }
821
+ free(key);
822
+
823
if (suc->update.type == SM_UPDATE_NONE
824
|| (suc->update.type == SM_UPDATE_UNSPECIFIED
813
- && sub->update_strategy.type == SM_UPDATE_NONE)) {
825
+ && update_type == SM_UPDATE_NONE)) {
826
strbuf_addf(out, _("Skipping submodule '%s'"), displaypath);
827
strbuf_addch(out, '\n');
828
goto cleanup;
@@ -822,6 +834,11 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
834
goto cleanup;
835
}
836
837
+ strbuf_reset(&sb);
838
+ strbuf_addf(&sb, "submodule.%s.url", sub->name);
839
+ if (repo_config_get_string_const(the_repository, sb.buf, &url))
840
+ url = sub->url;
841
+
842
strbuf_reset(&sb);
843
strbuf_addf(&sb, "%s/.git", ce->name);
844
needs_cloning = !file_exists(sb.buf);
@@ -851,7 +868,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
868
argv_array_push(&child->args, "--depth=1");
869
argv_array_pushl(&child->args, "--path", sub->path, NULL);
870
argv_array_pushl(&child->args, "--name", sub->name, NULL);
854
- argv_array_pushl(&child->args, "--url", sub->url, NULL);
871
+ argv_array_pushl(&child->args, "--url", url, NULL);
872
if (suc->references.nr) {
873
struct string_list_item *item;
874
for_each_string_list_item(item, &suc->references)
@@ -1025,9 +1042,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1042
if (pathspec.nr)
1043
suc.warn_if_uninitialized = 1;
1044
1028
- /* Overlay the parsed .gitmodules file with .git/config */
1045
gitmodules_config();
1030
- git_config(submodule_config, NULL);
1046
1047
run_processes_parallel(max_jobs,
1048
update_clone_get_next_task,
submodule.c
+26
-12
@@ -398,24 +398,38 @@ void die_path_inside_submodule(const struct index_state *istate,
398
}
399
}
400
401
-int parse_submodule_update_strategy(const char *value,
402
- struct submodule_update_strategy *dst)
401
+enum submodule_update_type parse_submodule_update_type(const char *value)
402
{
404
- free((void*)dst->command);
405
- dst->command = NULL;
403
if (!strcmp(value, "none"))
407
- dst->type = SM_UPDATE_NONE;
404
+ return SM_UPDATE_NONE;
405
else if (!strcmp(value, "checkout"))
409
- dst->type = SM_UPDATE_CHECKOUT;
406
+ return SM_UPDATE_CHECKOUT;
407
else if (!strcmp(value, "rebase"))
411
- dst->type = SM_UPDATE_REBASE;
408
+ return SM_UPDATE_REBASE;
409
else if (!strcmp(value, "merge"))
413
- dst->type = SM_UPDATE_MERGE;
414
- else if (skip_prefix(value, "!", &value)) {
415
- dst->type = SM_UPDATE_COMMAND;
416
- dst->command = xstrdup(value);
417
- } else
410
+ return SM_UPDATE_MERGE;
411
+ else if (*value == '!')
412
+ return SM_UPDATE_COMMAND;
413
+ else
414
+ return SM_UPDATE_UNSPECIFIED;
415
+}
416
+
417
+int parse_submodule_update_strategy(const char *value,
418
+ struct submodule_update_strategy *dst)
419
+{
420
+ enum submodule_update_type type;
421
+
422
+ free((void*)dst->command);
423
+ dst->command = NULL;
424
+
425
+ type = parse_submodule_update_type(value);
426
+ if (type == SM_UPDATE_UNSPECIFIED)
427
return -1;
428
+
429
+ dst->type = type;
430
+ if (type == SM_UPDATE_COMMAND)
431
+ dst->command = xstrdup(value + 1);
432
+
433
return 0;
434
}
435
submodule.h
+1
@@ -62,6 +62,7 @@ extern void die_in_unpopulated_submodule(const struct index_state *istate,
62
const char *prefix);
63
extern void die_path_inside_submodule(const struct index_state *istate,
64
const struct pathspec *ps);
65
+extern enum submodule_update_type parse_submodule_update_type(const char *value);
66
extern int parse_submodule_update_strategy(const char *value,
67
struct submodule_update_strategy *dst);
68
extern const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);