summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-03-17 13:50:28 -0700
committerJunio C Hamano <gitster@pobox.com>2017-03-17 13:50:28 -0700
commit9c96637163ef26c7726e693984c2d4d9599d4e7e (patch)
tree23ff95a0b958cb006f75f155a3aef4b54c320ec9
parenta0393a298fecff8cdc17aba51245f29433520d81 (diff)
parentb16a991c1be5681b4b673d4343dfcc0c2f5ad498 (diff)
downloadgit-9c96637163ef26c7726e693984c2d4d9599d4e7e.tar.gz
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
-rw-r--r--builtin/revert.c21
-rwxr-xr-xt/t3502-cherry-pick-merge.sh9
2 files changed, 29 insertions, 1 deletions
diff --git a/builtin/revert.c b/builtin/revert.c
index 4ca5b51544..345d9586a7 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -54,6 +54,24 @@ static int option_parse_x(const struct option *opt,
return 0;
}
+static int option_parse_m(const struct option *opt,
+ const char *arg, int unset)
+{
+ struct replay_opts *replay = opt->value;
+ char *end;
+
+ if (unset) {
+ replay->mainline = 0;
+ return 0;
+ }
+
+ replay->mainline = strtol(arg, &end, 10);
+ if (*end || replay->mainline <= 0)
+ return opterror(opt, "expects a number greater than zero", 0);
+
+ return 0;
+}
+
LAST_ARG_MUST_BE_NULL
static void verify_opt_compatible(const char *me, const char *base_opt, ...)
{
@@ -84,7 +102,8 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")),
OPT_NOOP_NOARG('r', NULL),
OPT_BOOL('s', "signoff", &opts->signoff, N_("add Signed-off-by:")),
- OPT_INTEGER('m', "mainline", &opts->mainline, N_("parent number")),
+ OPT_CALLBACK('m', "mainline", opts, N_("parent-number"),
+ N_("select mainline parent"), option_parse_m),
OPT_RERERE_AUTOUPDATE(&opts->allow_rerere_auto),
OPT_STRING(0, "strategy", &opts->strategy, N_("strategy"), N_("merge strategy")),
OPT_CALLBACK('X', "strategy-option", &opts, N_("option"),
diff --git a/t/t3502-cherry-pick-merge.sh b/t/t3502-cherry-pick-merge.sh
index e37547f41a..b1602718f8 100755
--- a/t/t3502-cherry-pick-merge.sh
+++ b/t/t3502-cherry-pick-merge.sh
@@ -31,6 +31,15 @@ test_expect_success setup '
'
+test_expect_success 'cherry-pick -m complains of bogus numbers' '
+ # expect 129 here to distinguish between cases where
+ # there was nothing to cherry-pick
+ test_expect_code 129 git cherry-pick -m &&
+ test_expect_code 129 git cherry-pick -m foo b &&
+ test_expect_code 129 git cherry-pick -m -1 b &&
+ test_expect_code 129 git cherry-pick -m 0 b
+'
+
test_expect_success 'cherry-pick a non-merge with -m should fail' '
git reset --hard &&