[RFC PATCH] cherry-pick: set default `--mainline` parent to 1

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>From fbb0e1fef08a2abd7f1620134925788f7a0e011f Mon Sep 17 00:00:00 2001
From: "C.J. Jameson" <cjcjameson@xxxxxxxxx>
Date: Tue, 19 Mar 2019 17:57:31 -0700
Subject: [RFC PATCH] cherry-pick: set default `--mainline` parent to 1

When cherry-picking from a standard merge commit, the parent should
always be 1, as it has the meaningful new changes which were added to
the mainline. If the source commit is unique in some way and a user
wants to specify a value other than 1, they still can, but it's up to
them to be aware of which parent is which.

This builds on commit 37897bfc27 ("cherry-pick: do not error on
non-merge commits when '-m 1' is specified", 2018-12-14) which tolerated
`--mainline` for non-merge commits

Signed-off-by: C.J. Jameson <cjcjameson@xxxxxxxxx>
---
 Documentation/git-cherry-pick.txt |  6 +++---
 Documentation/git-revert.txt      |  6 +++---
 builtin/revert.c                  |  4 ++--
 t/t3502-cherry-pick-merge.sh      | 19 ++++++++++++++++++-
 4 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/Documentation/git-cherry-pick.txt
b/Documentation/git-cherry-pick.txt
index b8cfeec67e..ec526d4cb8 100644
--- a/Documentation/git-cherry-pick.txt
+++ b/Documentation/git-cherry-pick.txt
@@ -76,13 +76,13 @@ OPTIONS
  described above, and `-r` was to disable it.  Now the
  default is not to do `-x` so this option is a no-op.

--m parent-number::
---mainline parent-number::
+-m [parent-number]::
+--mainline [parent-number]::
  Usually you cannot cherry-pick a merge because you do not know which
  side of the merge should be considered the mainline.  This
  option specifies the parent number (starting from 1) of
  the mainline and allows cherry-pick to replay the change
- relative to the specified parent.
+ relative to the specified parent. The default parent-number is 1.

 -n::
 --no-commit::
diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt
index 837707a8fd..57192a7c34 100644
--- a/Documentation/git-revert.txt
+++ b/Documentation/git-revert.txt
@@ -46,13 +46,13 @@ OPTIONS
  message prior to committing the revert. This is the default if
  you run the command from a terminal.

--m parent-number::
---mainline parent-number::
+-m [parent-number]::
+--mainline [parent-number]::
  Usually you cannot revert a merge because you do not know which
  side of the merge should be considered the mainline.  This
  option specifies the parent number (starting from 1) of
  the mainline and allows revert to reverse the change
- relative to the specified parent.
+ relative to the specified parent. The default parent-number is 1.
 +
 Reverting a merge commit declares that you will never want the tree changes
 brought in by the merge.  As a result, later merges will only bring in tree
diff --git a/builtin/revert.c b/builtin/revert.c
index a47b53ceaf..280d1f00a9 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -105,8 +105,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_CALLBACK('m', "mainline", opts, N_("parent-number"),
-      N_("select mainline parent"), option_parse_m),
+ { OPTION_INTEGER, 'm', "mainline", &opts->mainline, N_("parent-number"),
+ N_("select mainline parent"), PARSE_OPT_OPTARG, NULL, 1 },
  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 8b635a196d..4f248be582 100755
--- a/t/t3502-cherry-pick-merge.sh
+++ b/t/t3502-cherry-pick-merge.sh
@@ -34,7 +34,6 @@ 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
@@ -67,6 +66,15 @@ test_expect_success 'cherry pick a merge (1)' '

 '

+test_expect_success 'cherry pick a merge with default parent (1)' '
+
+ git reset --hard &&
+ git checkout a^0 &&
+ git cherry-pick -m c &&
+ git diff --exit-code c
+
+'
+
 test_expect_success 'cherry pick a merge (2)' '

  git reset --hard &&
@@ -111,6 +119,15 @@ test_expect_success 'revert a merge (1)' '

 '

+test_expect_success 'revert a merge with default parent (1)' '
+
+ git reset --hard &&
+ git checkout c^0 &&
+ git revert -m 1 c &&
+ git diff --exit-code a --
+
+'
+
 test_expect_success 'revert a merge (2)' '

  git reset --hard &&
-- 
2.21.0



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux