Skip to content

Commit a6cfb9b

Browse files
pcloudsgitster
authored andcommitted
restore: disable overlay mode by default
Overlay mode is considered confusing when the command is about restoring files on worktree. Disable it by default. The user can still turn it on, or use 'git checkout' which still has overlay mode on by default. While at it, make the check in checkout_branch() stricter. Neither --overlay or --no-overlay should be accepted in branch switching mode. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent be8ed50 commit a6cfb9b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

builtin/checkout.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,9 +1274,9 @@ static int checkout_branch(struct checkout_opts *opts,
12741274
die(_("'%s' cannot be used with switching branches"),
12751275
"--patch");
12761276

1277-
if (!opts->overlay_mode)
1277+
if (opts->overlay_mode != -1)
12781278
die(_("'%s' cannot be used with switching branches"),
1279-
"--no-overlay");
1279+
"--[no]-overlay");
12801280

12811281
if (opts->writeout_stage)
12821282
die(_("'%s' cannot be used with switching branches"),
@@ -1399,7 +1399,6 @@ static struct option *add_checkout_path_options(struct checkout_opts *opts,
13991399
OPT_BOOL('p', "patch", &opts->patch_mode, N_("select hunks interactively")),
14001400
OPT_BOOL(0, "ignore-skip-worktree-bits", &opts->ignore_skipworktree,
14011401
N_("do not limit pathspecs to sparse entries only")),
1402-
OPT_BOOL(0, "overlay", &opts->overlay_mode, N_("use overlay mode (default)")),
14031402
OPT_END()
14041403
};
14051404
struct option *newopts = parse_options_concat(prevopts, options);
@@ -1419,7 +1418,6 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
14191418
opts->overwrite_ignore = 1;
14201419
opts->prefix = prefix;
14211420
opts->show_progress = -1;
1422-
opts->overlay_mode = -1;
14231421

14241422
git_config(git_checkout_config, opts);
14251423

@@ -1593,6 +1591,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
15931591
OPT_BOOL('l', NULL, &opts.new_branch_log, N_("create reflog for new branch")),
15941592
OPT_BOOL(0, "guess", &opts.dwim_new_local_branch,
15951593
N_("second guess 'git checkout <no-such-branch>' (default)")),
1594+
OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode (default)")),
15961595
OPT_END()
15971596
};
15981597
int ret;
@@ -1607,6 +1606,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
16071606
opts.can_switch_when_in_progress = 1;
16081607
opts.orphan_from_empty_tree = 0;
16091608
opts.empty_pathspec_ok = 1;
1609+
opts.overlay_mode = -1;
16101610

16111611
options = parse_options_dup(checkout_options);
16121612
options = add_common_options(&opts, options);
@@ -1645,6 +1645,7 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
16451645
opts.implicit_detach = 0;
16461646
opts.can_switch_when_in_progress = 0;
16471647
opts.orphan_from_empty_tree = 1;
1648+
opts.overlay_mode = -1;
16481649

16491650
options = parse_options_dup(switch_options);
16501651
options = add_common_options(&opts, options);
@@ -1663,6 +1664,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
16631664
struct option restore_options[] = {
16641665
OPT_STRING('s', "source", &opts.from_treeish, "<tree-ish>",
16651666
N_("where the checkout from")),
1667+
OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode")),
16661668
OPT_END()
16671669
};
16681670
int ret;
@@ -1671,6 +1673,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
16711673
opts.accept_ref = 0;
16721674
opts.accept_pathspec = 1;
16731675
opts.empty_pathspec_ok = 0;
1676+
opts.overlay_mode = 0;
16741677

16751678
options = parse_options_dup(restore_options);
16761679
options = add_common_options(&opts, options);

0 commit comments

Comments
 (0)