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 <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 a6cfb9ba360d975dd38b2e6e77a88d2c8fe8d323
1 file changed +7 -4
builtin/checkout.c
+7 -4
@@ -1274,9 +1274,9 @@ static int checkout_branch(struct checkout_opts *opts,
1274 die(_("'%s' cannot be used with switching branches"),
1275 "--patch");
1276
1277 - if (!opts->overlay_mode)
1277 + if (opts->overlay_mode != -1)
1278 die(_("'%s' cannot be used with switching branches"),
1279 - "--no-overlay");
1279 + "--[no]-overlay");
1280
1281 if (opts->writeout_stage)
1282 die(_("'%s' cannot be used with switching branches"),
@@ -1399,7 +1399,6 @@ static struct option *add_checkout_path_options(struct checkout_opts *opts,
1399 OPT_BOOL('p', "patch", &opts->patch_mode, N_("select hunks interactively")),
1400 OPT_BOOL(0, "ignore-skip-worktree-bits", &opts->ignore_skipworktree,
1401 N_("do not limit pathspecs to sparse entries only")),
1402 - OPT_BOOL(0, "overlay", &opts->overlay_mode, N_("use overlay mode (default)")),
1402 OPT_END()
1403 };
1404 struct option *newopts = parse_options_concat(prevopts, options);
@@ -1419,7 +1418,6 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
1418 opts->overwrite_ignore = 1;
1419 opts->prefix = prefix;
1420 opts->show_progress = -1;
1422 - opts->overlay_mode = -1;
1421
1422 git_config(git_checkout_config, opts);
1423
@@ -1593,6 +1591,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1591 OPT_BOOL('l', NULL, &opts.new_branch_log, N_("create reflog for new branch")),
1592 OPT_BOOL(0, "guess", &opts.dwim_new_local_branch,
1593 N_("second guess 'git checkout <no-such-branch>' (default)")),
1594 + OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode (default)")),
1595 OPT_END()
1596 };
1597 int ret;
@@ -1607,6 +1606,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1606 opts.can_switch_when_in_progress = 1;
1607 opts.orphan_from_empty_tree = 0;
1608 opts.empty_pathspec_ok = 1;
1609 + opts.overlay_mode = -1;
1610
1611 options = parse_options_dup(checkout_options);
1612 options = add_common_options(&opts, options);
@@ -1645,6 +1645,7 @@ int cmd_switch(int argc, const char **argv, const char *prefix)
1645 opts.implicit_detach = 0;
1646 opts.can_switch_when_in_progress = 0;
1647 opts.orphan_from_empty_tree = 1;
1648 + opts.overlay_mode = -1;
1649
1650 options = parse_options_dup(switch_options);
1651 options = add_common_options(&opts, options);
@@ -1663,6 +1664,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
1664 struct option restore_options[] = {
1665 OPT_STRING('s', "source", &opts.from_treeish, "<tree-ish>",
1666 N_("where the checkout from")),
1667 + OPT_BOOL(0, "overlay", &opts.overlay_mode, N_("use overlay mode")),
1668 OPT_END()
1669 };
1670 int ret;
@@ -1671,6 +1673,7 @@ int cmd_restore(int argc, const char **argv, const char *prefix)
1673 opts.accept_ref = 0;
1674 opts.accept_pathspec = 1;
1675 opts.empty_pathspec_ok = 0;
1676 + opts.overlay_mode = 0;
1677
1678 options = parse_options_dup(restore_options);
1679 options = add_common_options(&opts, options);