Skip to content

Commit 8f12108

Browse files
avargitster
authored andcommitted
submodule--helper: understand --checkout, --merge and --rebase synonyms
Understand --checkout, --merge and --rebase synonyms for --update={checkout,merge,rebase}, as well as the short options that 'git submodule' itself understands. This removes a difference between the CLI API of "git submodule" and "git submodule--helper", making it easier to make the latter an alias for the former. See 4830868 (git submodule update: have a dedicated helper for cloning, 2016-02-29) for the initial addition of --update. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 36d4516 commit 8f12108

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

builtin/submodule--helper.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,23 @@ static void ensure_core_worktree(const char *path)
24042404
}
24052405
}
24062406

2407+
static const char *submodule_update_type_to_label(enum submodule_update_type type)
2408+
{
2409+
switch (type) {
2410+
case SM_UPDATE_CHECKOUT:
2411+
return "checkout";
2412+
case SM_UPDATE_MERGE:
2413+
return "merge";
2414+
case SM_UPDATE_REBASE:
2415+
return "rebase";
2416+
case SM_UPDATE_UNSPECIFIED:
2417+
case SM_UPDATE_NONE:
2418+
case SM_UPDATE_COMMAND:
2419+
break;
2420+
}
2421+
BUG("unreachable with type %d", type);
2422+
}
2423+
24072424
static void update_data_to_args(struct update_data *update_data, struct strvec *args)
24082425
{
24092426
strvec_pushl(args, "submodule--helper", "update", "--recursive", NULL);
@@ -2582,6 +2599,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
25822599
struct update_data opt = UPDATE_DATA_INIT;
25832600
struct list_objects_filter_options filter_options;
25842601
int ret;
2602+
enum submodule_update_type update_type = SM_UPDATE_UNSPECIFIED;
25852603

25862604
struct option module_update_options[] = {
25872605
OPT__FORCE(&opt.force, N_("force checkout updates"), 0),
@@ -2603,6 +2621,15 @@ static int module_update(int argc, const char **argv, const char *prefix)
26032621
OPT_STRING(0, "update", &opt.update_default,
26042622
N_("string"),
26052623
N_("rebase, merge, checkout or none")),
2624+
OPT_SET_INT(0, "checkout", &update_type,
2625+
N_("use the 'checkout' update strategy (default)"),
2626+
SM_UPDATE_CHECKOUT),
2627+
OPT_SET_INT('m', "merge", &update_type,
2628+
N_("use the 'merge' update strategy"),
2629+
SM_UPDATE_MERGE),
2630+
OPT_SET_INT('r', "rebase", &update_type,
2631+
N_("use the 'rebase' update strategy"),
2632+
SM_UPDATE_REBASE),
26062633
OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
26072634
N_("reference repository")),
26082635
OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2652,6 +2679,9 @@ static int module_update(int argc, const char **argv, const char *prefix)
26522679

26532680
opt.filter_options = &filter_options;
26542681

2682+
if (update_type != SM_UPDATE_UNSPECIFIED)
2683+
opt.update_default = submodule_update_type_to_label(update_type);
2684+
26552685
if (opt.update_default)
26562686
if (parse_submodule_update_strategy(opt.update_default,
26572687
&opt.update_strategy) < 0)

git-submodule.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ require_init=
4040
files=
4141
remote=
4242
nofetch=
43-
update=
43+
rebase=
44+
merge=
45+
checkout=
4446
custom_name=
4547
depth=
4648
progress=
@@ -260,7 +262,7 @@ cmd_update()
260262
force=$1
261263
;;
262264
-r|--rebase)
263-
update="rebase"
265+
rebase=1
264266
;;
265267
--reference)
266268
case "$2" in '') usage ;; esac
@@ -274,13 +276,13 @@ cmd_update()
274276
dissociate=1
275277
;;
276278
-m|--merge)
277-
update="merge"
279+
merge=1
278280
;;
279281
--recursive)
280282
recursive=1
281283
;;
282284
--checkout)
283-
update="checkout"
285+
checkout=1
284286
;;
285287
--recommend-shallow)
286288
recommend_shallow="--recommend-shallow"
@@ -341,7 +343,9 @@ cmd_update()
341343
${init:+--init} \
342344
${nofetch:+--no-fetch} \
343345
${wt_prefix:+--prefix "$wt_prefix"} \
344-
${update:+--update "$update"} \
346+
${rebase:+--rebase} \
347+
${merge:+--merge} \
348+
${checkout:+--checkout} \
345349
${reference:+"$reference"} \
346350
${dissociate:+"--dissociate"} \
347351
${depth:+"$depth"} \

0 commit comments

Comments
 (0)