Skip to content

Commit 3821eb6

Browse files
committed
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 <[email protected]>
1 parent fb7d80e commit 3821eb6

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

builtin/reset.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,18 +334,25 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
334334
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
335335
OPT_BOOL(0, "no-refresh", &no_refresh,
336336
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),
346352
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),
349356
OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
350357
OPT_BOOL('N', "intent-to-add", &intent_to_add,
351358
N_("record only the fact that removed paths will be added later")),

t/t7102-reset.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ check_changes () {
7171
done | test_cmp .cat_expect -
7272
}
7373

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+
7484
test_expect_success 'reset --hard message' '
7585
hex=$(git log -1 --format="%h") &&
7686
git reset --hard >.actual &&

0 commit comments

Comments
 (0)