Skip to content

Commit bad649b

Browse files
authored
Merge pull request #4 from epage/cherry
fix(ops): Actually find parent
2 parents 334a32b + 19d33bd commit bad649b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ops.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ pub fn cherry_pick(
5151
head_id: git2::Oid,
5252
cherry_id: git2::Oid,
5353
) -> Result<git2::Oid, git2::Error> {
54-
let base_id = repo.merge_base(head_id, cherry_id).unwrap_or(cherry_id);
54+
let cherry_commit = repo.find_commit(cherry_id)?;
55+
let base_id = match cherry_commit.parent_count() {
56+
0 => cherry_id,
57+
1 => cherry_commit.parent_id(0)?,
58+
_ => cherry_commit
59+
.parent_ids()
60+
.find(|id| *id == head_id)
61+
.map(Result::Ok)
62+
.unwrap_or_else(|| cherry_commit.parent_id(0))?,
63+
};
5564
if base_id == head_id {
5665
// Already on top of the intended base
5766
return Ok(cherry_id);
@@ -60,7 +69,6 @@ pub fn cherry_pick(
6069
let base_ann_commit = repo.find_annotated_commit(base_id)?;
6170
let head_ann_commit = repo.find_annotated_commit(head_id)?;
6271
let cherry_ann_commit = repo.find_annotated_commit(cherry_id)?;
63-
let cherry_commit = repo.find_commit(cherry_id)?;
6472
let mut rebase = repo.rebase(
6573
Some(&cherry_ann_commit),
6674
Some(&base_ann_commit),

0 commit comments

Comments
 (0)