Skip to content

Commit d78f991

Browse files
committed
Getting the stack branch head oid now has a fallback to CommitOrChangeId
1 parent aa87980 commit d78f991

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

crates/gitbutler-stack/src/stack_branch.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,19 @@ impl StackBranch {
258258
}
259259

260260
pub fn head_oid(&self, repo: &gix::Repository) -> Result<git2::Oid> {
261-
let mut reference = repo.find_reference(&self.name)?;
262-
let commit = reference.peel_to_commit()?;
263-
Ok(commit.id.to_git2())
261+
if let Some(mut reference) = repo.try_find_reference(&self.name)? {
262+
let commit = reference.peel_to_commit()?;
263+
Ok(commit.id.to_git2())
264+
} else if let CommitOrChangeId::CommitId(id) = &self.head {
265+
self.set_real_reference(repo, &self.head)?;
266+
Ok(git2::Oid::from_str(id)?)
267+
} else {
268+
Err(anyhow::anyhow!(
269+
"No reference found for branch {}. CommitOrChangeId is {}",
270+
&self.name,
271+
&self.head
272+
))
273+
}
264274
}
265275

266276
/// Returns a fully qualified reference with the supplied remote e.g. `refs/remotes/origin/base-branch-improvements`

0 commit comments

Comments
 (0)