Skip to content

Commit e672bc4

Browse files
committed
Merge branch 'jc/parse-options-reset'
Command line parser fix. * jc/parse-options-reset: reset: reject --no-(mixed|soft|hard|merge|keep) option
2 parents d6966f6 + 3821eb6 commit e672bc4

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
@@ -338,18 +338,25 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
338338
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
339339
OPT_BOOL(0, "no-refresh", &no_refresh,
340340
N_("skip refreshing the index after reset")),
341-
OPT_SET_INT(0, "mixed", &reset_type,
342-
N_("reset HEAD and index"), MIXED),
343-
OPT_SET_INT(0, "soft", &reset_type, N_("reset only HEAD"), SOFT),
344-
OPT_SET_INT(0, "hard", &reset_type,
345-
N_("reset HEAD, index and working tree"), HARD),
346-
OPT_SET_INT(0, "merge", &reset_type,
347-
N_("reset HEAD, index and working tree"), MERGE),
348-
OPT_SET_INT(0, "keep", &reset_type,
349-
N_("reset HEAD but keep local changes"), KEEP),
341+
OPT_SET_INT_F(0, "mixed", &reset_type,
342+
N_("reset HEAD and index"),
343+
MIXED, PARSE_OPT_NONEG),
344+
OPT_SET_INT_F(0, "soft", &reset_type,
345+
N_("reset only HEAD"),
346+
SOFT, PARSE_OPT_NONEG),
347+
OPT_SET_INT_F(0, "hard", &reset_type,
348+
N_("reset HEAD, index and working tree"),
349+
HARD, PARSE_OPT_NONEG),
350+
OPT_SET_INT_F(0, "merge", &reset_type,
351+
N_("reset HEAD, index and working tree"),
352+
MERGE, PARSE_OPT_NONEG),
353+
OPT_SET_INT_F(0, "keep", &reset_type,
354+
N_("reset HEAD but keep local changes"),
355+
KEEP, PARSE_OPT_NONEG),
350356
OPT_CALLBACK_F(0, "recurse-submodules", NULL,
351-
"reset", "control recursive updating of submodules",
352-
PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater),
357+
"reset", "control recursive updating of submodules",
358+
PARSE_OPT_OPTARG,
359+
option_parse_recurse_submodules_worktree_updater),
353360
OPT_BOOL('p', "patch", &patch_mode, N_("select hunks interactively")),
354361
OPT_BOOL('N', "intent-to-add", &intent_to_add,
355362
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)