Skip to content

Commit ec6141a

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 177257c commit ec6141a

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

builtin/submodule--helper.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,10 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
780780
struct strbuf *out)
781781
{
782782
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;
783787
struct strbuf displaypath_sb = STRBUF_INIT;
784788
struct strbuf sb = STRBUF_INIT;
785789
const char *displaypath = NULL;
@@ -808,9 +812,17 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
808812
goto cleanup;
809813
}
810814

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+
811823
if (suc->update.type == SM_UPDATE_NONE
812824
|| (suc->update.type == SM_UPDATE_UNSPECIFIED
813-
&& sub->update_strategy.type == SM_UPDATE_NONE)) {
825+
&& update_type == SM_UPDATE_NONE)) {
814826
strbuf_addf(out, _("Skipping submodule '%s'"), displaypath);
815827
strbuf_addch(out, '\n');
816828
goto cleanup;
@@ -822,6 +834,11 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
822834
goto cleanup;
823835
}
824836

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+
825842
strbuf_reset(&sb);
826843
strbuf_addf(&sb, "%s/.git", ce->name);
827844
needs_cloning = !file_exists(sb.buf);
@@ -851,7 +868,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
851868
argv_array_push(&child->args, "--depth=1");
852869
argv_array_pushl(&child->args, "--path", sub->path, NULL);
853870
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);
855872
if (suc->references.nr) {
856873
struct string_list_item *item;
857874
for_each_string_list_item(item, &suc->references)
@@ -1025,9 +1042,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
10251042
if (pathspec.nr)
10261043
suc.warn_if_uninitialized = 1;
10271044

1028-
/* Overlay the parsed .gitmodules file with .git/config */
10291045
gitmodules_config();
1030-
git_config(submodule_config, NULL);
10311046

10321047
run_processes_parallel(max_jobs,
10331048
update_clone_get_next_task,

submodule.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,24 +398,38 @@ void die_path_inside_submodule(const struct index_state *istate,
398398
}
399399
}
400400

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)
403402
{
404-
free((void*)dst->command);
405-
dst->command = NULL;
406403
if (!strcmp(value, "none"))
407-
dst->type = SM_UPDATE_NONE;
404+
return SM_UPDATE_NONE;
408405
else if (!strcmp(value, "checkout"))
409-
dst->type = SM_UPDATE_CHECKOUT;
406+
return SM_UPDATE_CHECKOUT;
410407
else if (!strcmp(value, "rebase"))
411-
dst->type = SM_UPDATE_REBASE;
408+
return SM_UPDATE_REBASE;
412409
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)
418427
return -1;
428+
429+
dst->type = type;
430+
if (type == SM_UPDATE_COMMAND)
431+
dst->command = xstrdup(value + 1);
432+
419433
return 0;
420434
}
421435

submodule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ extern void die_in_unpopulated_submodule(const struct index_state *istate,
6262
const char *prefix);
6363
extern void die_path_inside_submodule(const struct index_state *istate,
6464
const struct pathspec *ps);
65+
extern enum submodule_update_type parse_submodule_update_type(const char *value);
6566
extern int parse_submodule_update_strategy(const char *value,
6667
struct submodule_update_strategy *dst);
6768
extern const char *submodule_strategy_to_string(const struct submodule_update_strategy *s);

0 commit comments

Comments
 (0)