All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] cherry-pick: set default `--mainline` parent to 1
@ 2019-03-20  3:54 C.J. Jameson
  2019-03-20  4:45 ` Junio C Hamano
  2019-03-20  9:44 ` Duy Nguyen
  0 siblings, 2 replies; 23+ messages in thread
From: C.J. Jameson @ 2019-03-20  3:54 UTC (permalink / raw)
  To: git

From fbb0e1fef08a2abd7f1620134925788f7a0e011f Mon Sep 17 00:00:00 2001
From: "C.J. Jameson" <cjcjameson@gmail.com>
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@gmail.com>
---
 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

^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2019-03-25 15:42 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-20  3:54 [RFC PATCH] cherry-pick: set default `--mainline` parent to 1 C.J. Jameson
2019-03-20  4:45 ` Junio C Hamano
2019-03-20 12:01   ` Sergey Organov
2019-03-20 14:39     ` Elijah Newren
2019-03-20 15:59       ` Sergey Organov
2019-03-21  1:51         ` C.J. Jameson
2019-03-21  2:17       ` Junio C Hamano
2019-03-21  3:15         ` Junio C Hamano
2019-03-21  5:40           ` Sergey Organov
2019-03-21  5:47             ` Junio C Hamano
2019-03-21  6:12               ` Sergey Organov
2019-03-21  8:31                 ` Junio C Hamano
2019-03-21  8:31                 ` Junio C Hamano
2019-03-21 11:59                   ` Sergey Organov
2019-03-22  2:24                     ` Junio C Hamano
2019-03-22 15:22                       ` Sergey Organov
2019-03-22 18:27                         ` C.J. Jameson
2019-03-25 14:55                           ` Johannes Schindelin
2019-03-25 15:41                             ` C.J. Jameson
2019-03-21  6:54               ` Sergey Organov
2019-03-22 10:23         ` Johannes Schindelin
2019-03-22 10:13       ` Johannes Schindelin
2019-03-20  9:44 ` Duy Nguyen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.