restore: replace --force with --ignore-unmerged

Use a more specific option name to express its purpose. --force may come back as an alias of --ignore-unmerged and possibly more. But since this is a destructive operation, I don't see why we need to "force" anything more. We already don't hold back. When 'checkout --force' or 'restore --ignore-unmerged' is used, we may also print warnings about unmerged entries being ignore. Since this is not exactly warning (people tell us to do so), more informational, let it be suppressed if --quiet is given. This is a behavior change for git-checkout. PS. The diff looks a bit iffy since --force is moved to add_common_switch_branch_options() (i.e. for switching). But git-checkout is also doing switching and inherits this --force. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 25, 2019 at 16:45 UTC a5e5f399ca89cea574d11704d625a7b28b53de76
1 file changed +20 -9
builtin/checkout.c
+20 -9
@@ -68,6 +68,8 @@ struct checkout_opts {
68 int empty_pathspec_ok;
69 int checkout_index;
70 int checkout_worktree;
71 + const char *ignore_unmerged_opt;
72 + int ignore_unmerged;
73
74 const char *new_branch;
75 const char *new_branch_force;
@@ -409,8 +411,9 @@ static int checkout_paths(const struct checkout_opts *opts,
411 if (opts->new_branch_log)
412 die(_("'%s' cannot be used with updating paths"), "-l");
413
412 - if (opts->force && opts->patch_mode)
413 - die(_("'%s' cannot be used with updating paths"), "-f");
414 + if (opts->ignore_unmerged && opts->patch_mode)
415 + die(_("'%s' cannot be used with updating paths"),
416 + opts->ignore_unmerged_opt);
417
418 if (opts->force_detach)
419 die(_("'%s' cannot be used with updating paths"), "--detach");
@@ -418,8 +421,9 @@ static int checkout_paths(const struct checkout_opts *opts,
421 if (opts->merge && opts->patch_mode)
422 die(_("'%s' cannot be used with %s"), "--merge", "--patch");
423
421 - if (opts->force && opts->merge)
422 - die(_("'%s' cannot be used with %s"), "-f", "-m");
424 + if (opts->ignore_unmerged && opts->merge)
425 + die(_("'%s' cannot be used with %s"),
426 + opts->ignore_unmerged_opt, "-m");
427
428 if (opts->new_branch)
429 die(_("Cannot update paths and switch to branch '%s' at the same time."),
@@ -495,8 +499,9 @@ static int checkout_paths(const struct checkout_opts *opts,
499 if (ce->ce_flags & CE_MATCHED) {
500 if (!ce_stage(ce))
501 continue;
498 - if (opts->force) {
499 - warning(_("path '%s' is unmerged"), ce->name);
502 + if (opts->ignore_unmerged) {
503 + if (!opts->quiet)
504 + warning(_("path '%s' is unmerged"), ce->name);
505 } else if (opts->writeout_stage) {
506 errs |= check_stage(opts->writeout_stage, ce, pos, opts->overlay_mode);
507 } else if (opts->merge) {
@@ -1414,8 +1419,6 @@ static struct option *add_common_options(struct checkout_opts *opts,
1419 "checkout", "control recursive updating of submodules",
1420 PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
1421 OPT_BOOL(0, "progress", &opts->show_progress, N_("force progress reporting")),
1417 - OPT__FORCE(&opts->force, N_("force checkout (throw away local modifications)"),
1418 - PARSE_OPT_NOCOMPLETE),
1422 OPT_BOOL('m', "merge", &opts->merge, N_("perform a 3-way merge with the new branch")),
1423 OPT_STRING(0, "conflict", &opts->conflict_style, N_("style"),
1424 N_("conflict style (merge or diff3)")),
@@ -1433,6 +1436,8 @@ static struct option *add_common_switch_branch_options(
1436 OPT_BOOL('d', "detach", &opts->force_detach, N_("detach HEAD at named commit")),
1437 OPT_SET_INT('t', "track", &opts->track, N_("set upstream info for new branch"),
1438 BRANCH_TRACK_EXPLICIT),
1439 + OPT__FORCE(&opts->force, N_("force checkout (throw away local modifications)"),
1440 + PARSE_OPT_NOCOMPLETE),
1441 OPT_STRING(0, "orphan", &opts->new_orphan_branch, N_("new-branch"), N_("new unparented branch")),
1442 OPT_BOOL_F(0, "overwrite-ignore", &opts->overwrite_ignore,
1443 N_("update ignored files (default)"),
@@ -1502,8 +1507,11 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1507 opts->merge = 1; /* implied */
1508 git_xmerge_config("merge.conflictstyle", opts->conflict_style, NULL);
1509 }
1505 - if (opts->force)
1510 + if (opts->force) {
1511 opts->discard_changes = 1;
1512 + opts->ignore_unmerged_opt = "--force";
1513 + opts->ignore_unmerged = 1;
1514 + }
1515
1516 if ((!!opts->new_branch + !!opts->new_branch_force + !!opts->new_orphan_branch) > 1)
1517 die(_("-b, -B and --orphan are mutually exclusive"));
@@ -1750,6 +1758,8 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
1758 N_("restore the index")),
1759 OPT_BOOL('W', "worktree", &opts.checkout_worktree,
1760 N_("restore the working tree (default)")),
1761 + OPT_BOOL(0, "ignore-unmerged", &opts.ignore_unmerged,
1762 + N_("ignore unmerged entries")),
1763 OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode")),
1764 OPT_END()
1765 };
@@ -1762,6 +1772,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
1772 opts.overlay_mode = 0;
1773 opts.checkout_index = -1; /* default off */
1774 opts.checkout_worktree = -2; /* default on */
1775 + opts.ignore_unmerged_opt = "--ignore-unmerged";
1776
1777 options = parse_options_dup(restore_options);
1778 options = add_common_options(&opts, options);