Skip to content

Commit b268078

Browse files
committed
Merge branch 'gc/submodule-update' into seen
* gc/submodule-update: submodule update: remove never-used expansion submodule update: stop parsing options in .sh submodule update: remove -v, pass --quiet submodule--helper update: use one param per type submodule update: pass --require-init and --init submodule update: pass options with stuck forms submodule update: pass options containing "[no-]" submodule update: remove intermediate parsing
2 parents 561cb76 + 349a360 commit b268078

File tree

3 files changed

+29
-145
lines changed

3 files changed

+29
-145
lines changed

builtin/submodule--helper.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ static int module_clone(int argc, const char **argv, const char *prefix)
18181818
static void determine_submodule_update_strategy(struct repository *r,
18191819
int just_cloned,
18201820
const char *path,
1821-
const char *update,
1821+
enum submodule_update_type update,
18221822
struct submodule_update_strategy *out)
18231823
{
18241824
const struct submodule *sub = submodule_from_path(r, null_oid(), path);
@@ -1828,9 +1828,7 @@ static void determine_submodule_update_strategy(struct repository *r,
18281828
key = xstrfmt("submodule.%s.update", sub->name);
18291829

18301830
if (update) {
1831-
if (parse_submodule_update_strategy(update, out) < 0)
1832-
die(_("Invalid update mode '%s' for submodule path '%s'"),
1833-
update, path);
1831+
out->type = update;
18341832
} else if (!repo_config_get_string_tmp(r, key, &val)) {
18351833
if (parse_submodule_update_strategy(val, out) < 0)
18361834
die(_("Invalid update mode '%s' configured for submodule path '%s'"),
@@ -1882,7 +1880,6 @@ struct update_data {
18821880
const char *prefix;
18831881
const char *recursive_prefix;
18841882
const char *displaypath;
1885-
const char *update_default;
18861883
struct object_id suboid;
18871884
struct string_list references;
18881885
struct submodule_update_strategy update_strategy;
@@ -1892,6 +1889,7 @@ struct update_data {
18921889
int max_jobs;
18931890
int single_branch;
18941891
int recommend_shallow;
1892+
enum submodule_update_type update_default;
18951893
unsigned int require_init;
18961894
unsigned int force;
18971895
unsigned int quiet;
@@ -2429,8 +2427,20 @@ static void update_data_to_args(struct update_data *update_data, struct strvec *
24292427
strvec_push(args, "--require-init");
24302428
if (update_data->depth)
24312429
strvec_pushf(args, "--depth=%d", update_data->depth);
2432-
if (update_data->update_default)
2433-
strvec_pushl(args, "--update", update_data->update_default, NULL);
2430+
switch (update_data->update_default) {
2431+
case SM_UPDATE_MERGE:
2432+
strvec_push(args, "--merge");
2433+
break;
2434+
case SM_UPDATE_CHECKOUT:
2435+
strvec_push(args, "--checkout");
2436+
break;
2437+
case SM_UPDATE_REBASE:
2438+
strvec_push(args, "--rebase");
2439+
break;
2440+
default:
2441+
break;
2442+
}
2443+
24342444
if (update_data->references.nr) {
24352445
struct string_list_item *item;
24362446
for_each_string_list_item(item, &update_data->references)
@@ -2600,9 +2610,12 @@ static int module_update(int argc, const char **argv, const char *prefix)
26002610
N_("path"),
26012611
N_("path into the working tree, across nested "
26022612
"submodule boundaries")),
2603-
OPT_STRING(0, "update", &opt.update_default,
2604-
N_("string"),
2605-
N_("rebase, merge, checkout or none")),
2613+
OPT_SET_INT(0, "checkout", &opt.update_default,
2614+
N_("update using checkout"), SM_UPDATE_CHECKOUT),
2615+
OPT_SET_INT('r', "rebase", &opt.update_default,
2616+
N_("update using rebase"), SM_UPDATE_REBASE),
2617+
OPT_SET_INT('m', "merge", &opt.update_default,
2618+
N_("update using merge"), SM_UPDATE_MERGE),
26062619
OPT_STRING_LIST(0, "reference", &opt.references, N_("repo"),
26072620
N_("reference repository")),
26082621
OPT_BOOL(0, "dissociate", &opt.dissociate,
@@ -2642,6 +2655,10 @@ static int module_update(int argc, const char **argv, const char *prefix)
26422655
argc = parse_options(argc, argv, prefix, module_update_options,
26432656
git_submodule_helper_usage, 0);
26442657

2658+
if (opt.require_init) {
2659+
opt.init = 1;
2660+
}
2661+
26452662
if (filter_options.choice && !opt.init) {
26462663
usage_with_options(git_submodule_helper_usage,
26472664
module_update_options);
@@ -2650,9 +2667,7 @@ static int module_update(int argc, const char **argv, const char *prefix)
26502667
opt.filter_options = &filter_options;
26512668

26522669
if (opt.update_default)
2653-
if (parse_submodule_update_strategy(opt.update_default,
2654-
&opt.update_strategy) < 0)
2655-
die(_("bad value for update parameter"));
2670+
opt.update_strategy.type = opt.update_default;
26562671

26572672
if (module_list_compute(argc, argv, prefix, &pathspec, &opt.list) < 0) {
26582673
list_objects_filter_release(&filter_options);

git-submodule.sh

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,14 @@ export GIT_PROTOCOL_FROM_USER
3232
command=
3333
branch=
3434
force=
35-
reference=
3635
cached=
3736
recursive=
38-
init=
39-
require_init=
4037
files=
41-
remote=
42-
nofetch=
43-
update=
4438
prefix=
4539
custom_name=
4640
depth=
4741
progress=
4842
dissociate=
49-
single_branch=
50-
jobs=
51-
recommend_shallow=
52-
filter=
5343

5444
isnumber()
5545
{
@@ -246,129 +236,8 @@ cmd_deinit()
246236
#
247237
cmd_update()
248238
{
249-
# parse $args after "submodule ... update".
250-
while test $# -ne 0
251-
do
252-
case "$1" in
253-
-q|--quiet)
254-
GIT_QUIET=1
255-
;;
256-
-v)
257-
unset GIT_QUIET
258-
;;
259-
--progress)
260-
progress=1
261-
;;
262-
-i|--init)
263-
init=1
264-
;;
265-
--require-init)
266-
init=1
267-
require_init=1
268-
;;
269-
--remote)
270-
remote=1
271-
;;
272-
-N|--no-fetch)
273-
nofetch=1
274-
;;
275-
-f|--force)
276-
force=$1
277-
;;
278-
-r|--rebase)
279-
update="rebase"
280-
;;
281-
--reference)
282-
case "$2" in '') usage ;; esac
283-
reference="--reference=$2"
284-
shift
285-
;;
286-
--reference=*)
287-
reference="$1"
288-
;;
289-
--dissociate)
290-
dissociate=1
291-
;;
292-
-m|--merge)
293-
update="merge"
294-
;;
295-
--recursive)
296-
recursive=1
297-
;;
298-
--checkout)
299-
update="checkout"
300-
;;
301-
--recommend-shallow)
302-
recommend_shallow="--recommend-shallow"
303-
;;
304-
--no-recommend-shallow)
305-
recommend_shallow="--no-recommend-shallow"
306-
;;
307-
--depth)
308-
case "$2" in '') usage ;; esac
309-
depth="--depth=$2"
310-
shift
311-
;;
312-
--depth=*)
313-
depth=$1
314-
;;
315-
-j|--jobs)
316-
case "$2" in '') usage ;; esac
317-
jobs="--jobs=$2"
318-
shift
319-
;;
320-
--jobs=*)
321-
jobs=$1
322-
;;
323-
--single-branch)
324-
single_branch="--single-branch"
325-
;;
326-
--no-single-branch)
327-
single_branch="--no-single-branch"
328-
;;
329-
--filter)
330-
case "$2" in '') usage ;; esac
331-
filter="--filter=$2"
332-
shift
333-
;;
334-
--filter=*)
335-
filter="$1"
336-
;;
337-
--)
338-
shift
339-
break
340-
;;
341-
-*)
342-
usage
343-
;;
344-
*)
345-
break
346-
;;
347-
esac
348-
shift
349-
done
350-
351239
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper update \
352-
${GIT_QUIET:+--quiet} \
353-
${force:+--force} \
354-
${progress:+"--progress"} \
355-
${remote:+--remote} \
356-
${recursive:+--recursive} \
357-
${init:+--init} \
358-
${nofetch:+--no-fetch} \
359240
${wt_prefix:+--prefix "$wt_prefix"} \
360-
${prefix:+--recursive-prefix "$prefix"} \
361-
${update:+--update "$update"} \
362-
${reference:+"$reference"} \
363-
${dissociate:+"--dissociate"} \
364-
${depth:+"$depth"} \
365-
${require_init:+--require-init} \
366-
${dissociate:+"--dissociate"} \
367-
$single_branch \
368-
$recommend_shallow \
369-
$jobs \
370-
$filter \
371-
-- \
372241
"$@"
373242
}
374243

t/t7406-submodule-update.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ test_expect_success 'submodule update --quiet passes quietness to merge/rebase'
10741074
git submodule update --rebase --quiet >out 2>err &&
10751075
test_must_be_empty out &&
10761076
test_must_be_empty err &&
1077-
git submodule update --rebase -v >out 2>err &&
1077+
git submodule update --rebase >out 2>err &&
10781078
test_file_not_empty out &&
10791079
test_must_be_empty err
10801080
)

0 commit comments

Comments
 (0)