reset: reject --no-(mixed|soft|hard|merge|keep) option

"git reset --no-mixed" behaved exactly like "git reset --mixed", which was nonsense. If there were only two kinds, e.g. "mixed" vs "separate", it might have made sense to make "git reset --no-mixed" behave identically to "git reset --separate" and vice-versa, but because we have many types of reset, let's just forbid "--no-mixed" and negated form of other types. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 19, 2023 at 06:37 UTC 3821eb6c3dedba1c57522a1254a916f5ad0d15dc
2 files changed +28 -11
builtin/reset.c
+18 -11
@@ -334,18 +334,25 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
334 OPT__QUIET(&quiet, N_("be quiet, only report errors")),
335 OPT_BOOL(0, "no-refresh", &no_refresh,
336 N_("skip refreshing the index after reset")),
337 - OPT_SET_INT(0, "mixed", &reset_type,
338 - N_("reset HEAD and index"), MIXED),
339 - OPT_SET_INT(0, "soft", &reset_type, N_("reset only HEAD"), SOFT),
340 - OPT_SET_INT(0, "hard", &reset_type,
341 - N_("reset HEAD, index and working tree"), HARD),
342 - OPT_SET_INT(0, "merge", &reset_type,
343 - N_("reset HEAD, index and working tree"), MERGE),
344 - OPT_SET_INT(0, "keep", &reset_type,
345 - N_("reset HEAD but keep local changes"), KEEP),
337 + OPT_SET_INT_F(0, "mixed", &reset_type,
338 + N_("reset HEAD and index"),
339 + MIXED, PARSE_OPT_NONEG),
340 + OPT_SET_INT_F(0, "soft", &reset_type,
341 + N_("reset only HEAD"),
342 + SOFT, PARSE_OPT_NONEG),
343 + OPT_SET_INT_F(0, "hard", &reset_type,
344 + N_("reset HEAD, index and working tree"),
345 + HARD, PARSE_OPT_NONEG),
346 + OPT_SET_INT_F(0, "merge", &reset_type,
347 + N_("reset HEAD, index and working tree"),
348 + MERGE, PARSE_OPT_NONEG),
349 + OPT_SET_INT_F(0, "keep", &reset_type,
350 + N_("reset HEAD but keep local changes"),
351 + KEEP, PARSE_OPT_NONEG),
352 OPT_CALLBACK_F(0, "recurse-submodules", NULL,
347 - "reset", "control recursive updating of submodules",
348 - PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater),
353 + "reset", "control recursive updating of submodules",
354 + PARSE_OPT_OPTARG,
355 + option_parse_recurse_submodules_worktree_updater),
356 OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
357 OPT_BOOL('N', "intent-to-add", &intent_to_add,
358 N_("record only the fact that removed paths will be added later")),
t/t7102-reset.sh
+10
@@ -71,6 +71,16 @@ check_changes () {
71 done | test_cmp .cat_expect -
72 }
73
74 +# no negated form for various type of resets
75 +for opt in soft mixed hard merge keep
76 +do
77 + test_expect_success "no 'git reset --no-$opt'" '
78 + test_when_finished "rm -f err" &&
79 + test_must_fail git reset --no-$opt 2>err &&
80 + grep "error: unknown option .no-$opt." err
81 + '
82 +done
83 +
84 test_expect_success 'reset --hard message' '
85 hex=$(git log -1 --format="%h") &&
86 git reset --hard >.actual &&