Skip to content

Commit 5f50f33

Browse files
stefanbellergitster
authored andcommitted
submodule--helper update-clone: allow multiple references
Allow the user to pass in multiple references to update_clone. Currently this is only internal API, but once the shell script is replaced by a C version, this is needed. This fixes an API bug between the shell script and the helper. Currently the helper accepts "--reference" "--reference=foo" as a OPT_STRING whose value happens to be "--reference=foo", and then uses if (suc->reference) argv_array_push(&child->args, suc->reference) where suc->reference _is_ "--reference=foo" when invoking the underlying "git clone", it cancels out. With this change we omit one of the "--reference" arguments when passing references from the shell script to the helper. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 965dbea commit 5f50f33

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

builtin/submodule--helper.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ struct submodule_update_clone {
584584
/* configuration parameters which are passed on to the children */
585585
int quiet;
586586
int recommend_shallow;
587-
const char *reference;
587+
struct string_list references;
588588
const char *depth;
589589
const char *recursive_prefix;
590590
const char *prefix;
@@ -600,7 +600,8 @@ struct submodule_update_clone {
600600
int failed_clones_nr, failed_clones_alloc;
601601
};
602602
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
603-
SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, NULL, NULL, NULL, NULL, \
603+
SUBMODULE_UPDATE_STRATEGY_INIT, 0, -1, STRING_LIST_INIT_DUP, \
604+
NULL, NULL, NULL, \
604605
STRING_LIST_INIT_DUP, 0, NULL, 0, 0}
605606

606607

@@ -710,8 +711,11 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
710711
argv_array_pushl(&child->args, "--path", sub->path, NULL);
711712
argv_array_pushl(&child->args, "--name", sub->name, NULL);
712713
argv_array_pushl(&child->args, "--url", url, NULL);
713-
if (suc->reference)
714-
argv_array_push(&child->args, suc->reference);
714+
if (suc->references.nr) {
715+
struct string_list_item *item;
716+
for_each_string_list_item(item, &suc->references)
717+
argv_array_pushl(&child->args, "--reference", item->string, NULL);
718+
}
715719
if (suc->depth)
716720
argv_array_push(&child->args, suc->depth);
717721

@@ -830,7 +834,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
830834
OPT_STRING(0, "update", &update,
831835
N_("string"),
832836
N_("rebase, merge, checkout or none")),
833-
OPT_STRING(0, "reference", &suc.reference, N_("repo"),
837+
OPT_STRING_LIST(0, "reference", &suc.references, N_("repo"),
834838
N_("reference repository")),
835839
OPT_STRING(0, "depth", &suc.depth, "<depth>",
836840
N_("Create a shallow clone truncated to the "

git-submodule.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ cmd_update()
575575
${wt_prefix:+--prefix "$wt_prefix"} \
576576
${prefix:+--recursive-prefix "$prefix"} \
577577
${update:+--update "$update"} \
578-
${reference:+--reference "$reference"} \
578+
${reference:+"$reference"} \
579579
${depth:+--depth "$depth"} \
580580
${recommend_shallow:+"$recommend_shallow"} \
581581
${jobs:+$jobs} \

0 commit comments

Comments
 (0)