Skip to content

Commit 4ac9aeb

Browse files
committed
Merge branch 'bc/fix-cherry-pick-root'
* bc/fix-cherry-pick-root: builtin/revert.c: don't dereference a NULL pointer
2 parents 90d6bd5 + 6355e50 commit 4ac9aeb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

builtin/revert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ static int do_pick_commit(void)
442442
else
443443
parent = commit->parents->item;
444444

445-
if (allow_ff && !hashcmp(parent->object.sha1, head))
445+
if (allow_ff && parent && !hashcmp(parent->object.sha1, head))
446446
return fast_forward_to(commit->object.sha1, head);
447447

448448
if (parent && parse_commit(parent) < 0)

t/t3506-cherry-pick-ff.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,14 @@ test_expect_success 'cherry pick a merge relative to nonexistent parent with --f
9595
test_must_fail git cherry-pick --ff -m 3 C
9696
'
9797

98+
test_expect_success 'cherry pick a root commit with --ff' '
99+
git reset --hard first -- &&
100+
git rm file1 &&
101+
echo first >file2 &&
102+
git add file2 &&
103+
git commit --amend -m "file2" &&
104+
git cherry-pick --ff first &&
105+
test "$(git rev-parse --verify HEAD)" = "1df192cd8bc58a2b275d842cede4d221ad9000d1"
106+
'
107+
98108
test_done

0 commit comments

Comments
 (0)