Skip to content

Commit 77fbd96

Browse files
committed
Merge branch 'so/cherry-pick-always-allow-m1'
"git cherry-pick -m1" was forbidden when picking a non-merge commit, even though there _is_ parent number 1 for such a commit. This was done to avoid mistakes back when "cherry-pick" was about picking a single commit, but is no longer useful with "cherry-pick" that can pick a range of commits. Now the "-m$num" option is allowed when picking any commit, as long as $num names an existing parent of the commit. Technically this is a backward incompatible change; hopefully nobody is relying on the error-checking behaviour. * so/cherry-pick-always-allow-m1: t3506: validate '-m 1 -ff' is now accepted for non-merge commits t3502: validate '-m 1' argument is now accepted for non-merge commits cherry-pick: do not error on non-merge commits when '-m 1' is specified t3510: stop using '-m 1' to force failure mid-sequence of cherry-picks
2 parents 726f89c + 1c32013 commit 77fbd96

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

sequencer.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,9 +1790,13 @@ static int do_pick_commit(struct repository *r,
17901790
return error(_("commit %s does not have parent %d"),
17911791
oid_to_hex(&commit->object.oid), opts->mainline);
17921792
parent = p->item;
1793-
} else if (0 < opts->mainline)
1794-
return error(_("mainline was specified but commit %s is not a merge."),
1795-
oid_to_hex(&commit->object.oid));
1793+
} else if (1 < opts->mainline)
1794+
/*
1795+
* Non-first parent explicitly specified as mainline for
1796+
* non-merge commit
1797+
*/
1798+
return error(_("commit %s does not have parent %d"),
1799+
oid_to_hex(&commit->object.oid), opts->mainline);
17961800
else
17971801
parent = commit->parents->item;
17981802

t/t3502-cherry-pick-merge.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ test_expect_success 'cherry-pick -m complains of bogus numbers' '
4040
test_expect_code 129 git cherry-pick -m 0 b
4141
'
4242

43-
test_expect_success 'cherry-pick a non-merge with -m should fail' '
43+
test_expect_success 'cherry-pick explicit first parent of a non-merge' '
4444
4545
git reset --hard &&
4646
git checkout a^0 &&
47-
test_expect_code 128 git cherry-pick -m 1 b &&
48-
git diff --exit-code a --
47+
git cherry-pick -m 1 b &&
48+
git diff --exit-code c --
4949
5050
'
5151

@@ -84,12 +84,12 @@ test_expect_success 'cherry pick a merge relative to nonexistent parent should f
8484
8585
'
8686

87-
test_expect_success 'revert a non-merge with -m should fail' '
87+
test_expect_success 'revert explicit first parent of a non-merge' '
8888
8989
git reset --hard &&
9090
git checkout c^0 &&
91-
test_must_fail git revert -m 1 b &&
92-
git diff --exit-code c
91+
git revert -m 1 b &&
92+
git diff --exit-code a --
9393
9494
'
9595

t/t3506-cherry-pick-ff.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ test_expect_success 'merge setup' '
6464
git checkout -b new A
6565
'
6666

67-
test_expect_success 'cherry-pick a non-merge with --ff and -m should fail' '
67+
test_expect_success 'cherry-pick explicit first parent of a non-merge with --ff' '
6868
git reset --hard A -- &&
69-
test_must_fail git cherry-pick --ff -m 1 B &&
70-
git diff --exit-code A --
69+
git cherry-pick --ff -m 1 B &&
70+
git diff --exit-code C --
7171
'
7272

7373
test_expect_success 'cherry pick a merge with --ff but without -m should fail' '

t/t3510-cherry-pick-sequence.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,19 @@ test_expect_success 'cherry-pick mid-cherry-pick-sequence' '
6161

6262
test_expect_success 'cherry-pick persists opts correctly' '
6363
pristine_detach initial &&
64-
test_expect_code 128 git cherry-pick -s -m 1 --strategy=recursive -X patience -X ours initial..anotherpick &&
64+
# to make sure that the session to cherry-pick a sequence
65+
# gets interrupted, use a high-enough number that is larger
66+
# than the number of parents of any commit we have created
67+
mainline=4 &&
68+
test_expect_code 128 git cherry-pick -s -m $mainline --strategy=recursive -X patience -X ours initial..anotherpick &&
6569
test_path_is_dir .git/sequencer &&
6670
test_path_is_file .git/sequencer/head &&
6771
test_path_is_file .git/sequencer/todo &&
6872
test_path_is_file .git/sequencer/opts &&
6973
echo "true" >expect &&
7074
git config --file=.git/sequencer/opts --get-all options.signoff >actual &&
7175
test_cmp expect actual &&
72-
echo "1" >expect &&
76+
echo "$mainline" >expect &&
7377
git config --file=.git/sequencer/opts --get-all options.mainline >actual &&
7478
test_cmp expect actual &&
7579
echo "recursive" >expect &&

0 commit comments

Comments
 (0)