Skip to content

Commit 9c96637

Browse files
committed
Merge branch 'jk/cherry-pick-0-mainline'
"git revert -m 0 $merge_commit" complained that reverting a merge needs to say relative to which parent the reversion needs to happen, as if "-m 0" weren't given. The correct diagnosis is that "-m 0" does not refer to the first parent ("-m 1" does). This has been fixed. * jk/cherry-pick-0-mainline: cherry-pick: detect bogus arguments to --mainline
2 parents a0393a2 + b16a991 commit 9c96637

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

builtin/revert.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,24 @@ static int option_parse_x(const struct option *opt,
5454
return 0;
5555
}
5656

57+
static int option_parse_m(const struct option *opt,
58+
const char *arg, int unset)
59+
{
60+
struct replay_opts *replay = opt->value;
61+
char *end;
62+
63+
if (unset) {
64+
replay->mainline = 0;
65+
return 0;
66+
}
67+
68+
replay->mainline = strtol(arg, &end, 10);
69+
if (*end || replay->mainline <= 0)
70+
return opterror(opt, "expects a number greater than zero", 0);
71+
72+
return 0;
73+
}
74+
5775
LAST_ARG_MUST_BE_NULL
5876
static void verify_opt_compatible(const char *me, const char *base_opt, ...)
5977
{
@@ -84,7 +102,8 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
84102
OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")),
85103
OPT_NOOP_NOARG('r', NULL),
86104
OPT_BOOL('s', "signoff", &opts->signoff, N_("add Signed-off-by:")),
87-
OPT_INTEGER('m', "mainline", &opts->mainline, N_("parent number")),
105+
OPT_CALLBACK('m', "mainline", opts, N_("parent-number"),
106+
N_("select mainline parent"), option_parse_m),
88107
OPT_RERERE_AUTOUPDATE(&opts->allow_rerere_auto),
89108
OPT_STRING(0, "strategy", &opts->strategy, N_("strategy"), N_("merge strategy")),
90109
OPT_CALLBACK('X', "strategy-option", &opts, N_("option"),

t/t3502-cherry-pick-merge.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ test_expect_success setup '
3131
3232
'
3333

34+
test_expect_success 'cherry-pick -m complains of bogus numbers' '
35+
# expect 129 here to distinguish between cases where
36+
# there was nothing to cherry-pick
37+
test_expect_code 129 git cherry-pick -m &&
38+
test_expect_code 129 git cherry-pick -m foo b &&
39+
test_expect_code 129 git cherry-pick -m -1 b &&
40+
test_expect_code 129 git cherry-pick -m 0 b
41+
'
42+
3443
test_expect_success 'cherry-pick a non-merge with -m should fail' '
3544
3645
git reset --hard &&

0 commit comments

Comments
 (0)