Skip to content

Commit a5e5f39

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3a733ce commit a5e5f39

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

builtin/checkout.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ struct checkout_opts {
6868
int empty_pathspec_ok;
6969
int checkout_index;
7070
int checkout_worktree;
71+
const char *ignore_unmerged_opt;
72+
int ignore_unmerged;
7173

7274
const char *new_branch;
7375
const char *new_branch_force;
@@ -409,17 +411,19 @@ static int checkout_paths(const struct checkout_opts *opts,
409411
if (opts->new_branch_log)
410412
die(_("'%s' cannot be used with updating paths"), "-l");
411413

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);
414417

415418
if (opts->force_detach)
416419
die(_("'%s' cannot be used with updating paths"), "--detach");
417420

418421
if (opts->merge && opts->patch_mode)
419422
die(_("'%s' cannot be used with %s"), "--merge", "--patch");
420423

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");
423427

424428
if (opts->new_branch)
425429
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,
495499
if (ce->ce_flags & CE_MATCHED) {
496500
if (!ce_stage(ce))
497501
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);
500505
} else if (opts->writeout_stage) {
501506
errs |= check_stage(opts->writeout_stage, ce, pos, opts->overlay_mode);
502507
} else if (opts->merge) {
@@ -1414,8 +1419,6 @@ static struct option *add_common_options(struct checkout_opts *opts,
14141419
"checkout", "control recursive updating of submodules",
14151420
PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
14161421
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),
14191422
OPT_BOOL('m', "merge", &opts->merge, N_("perform a 3-way merge with the new branch")),
14201423
OPT_STRING(0, "conflict", &opts->conflict_style, N_("style"),
14211424
N_("conflict style (merge or diff3)")),
@@ -1433,6 +1436,8 @@ static struct option *add_common_switch_branch_options(
14331436
OPT_BOOL('d', "detach", &opts->force_detach, N_("detach HEAD at named commit")),
14341437
OPT_SET_INT('t', "track", &opts->track, N_("set upstream info for new branch"),
14351438
BRANCH_TRACK_EXPLICIT),
1439+
OPT__FORCE(&opts->force, N_("force checkout (throw away local modifications)"),
1440+
PARSE_OPT_NOCOMPLETE),
14361441
OPT_STRING(0, "orphan", &opts->new_orphan_branch, N_("new-branch"), N_("new unparented branch")),
14371442
OPT_BOOL_F(0, "overwrite-ignore", &opts->overwrite_ignore,
14381443
N_("update ignored files (default)"),
@@ -1502,8 +1507,11 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
15021507
opts->merge = 1; /* implied */
15031508
git_xmerge_config("merge.conflictstyle", opts->conflict_style, NULL);
15041509
}
1505-
if (opts->force)
1510+
if (opts->force) {
15061511
opts->discard_changes = 1;
1512+
opts->ignore_unmerged_opt = "--force";
1513+
opts->ignore_unmerged = 1;
1514+
}
15071515

15081516
if ((!!opts->new_branch + !!opts->new_branch_force + !!opts->new_orphan_branch) > 1)
15091517
die(_("-b, -B and --orphan are mutually exclusive"));
@@ -1750,6 +1758,8 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
17501758
N_("restore the index")),
17511759
OPT_BOOL('W', "worktree", &opts.checkout_worktree,
17521760
N_("restore the working tree (default)")),
1761+
OPT_BOOL(0, "ignore-unmerged", &opts.ignore_unmerged,
1762+
N_("ignore unmerged entries")),
17531763
OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode")),
17541764
OPT_END()
17551765
};
@@ -1762,6 +1772,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
17621772
opts.overlay_mode = 0;
17631773
opts.checkout_index = -1; /* default off */
17641774
opts.checkout_worktree = -2; /* default on */
1775+
opts.ignore_unmerged_opt = "--ignore-unmerged";
17651776

17661777
options = parse_options_dup(restore_options);
17671778
options = add_common_options(&opts, options);

0 commit comments

Comments
 (0)