Skip to content

Commit 9516094

Browse files
committed
Fix an issue where in some cases 'wrong' commits are shown in listed branches
This was because the merge base computed was wrong. Instead of relying on the default target.sha, which may have become stale, read the git reference of the default target
1 parent d03c9c1 commit 9516094

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

crates/gitbutler-stack/src/stack.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,15 @@ impl Stack {
310310
/// - If a target is not set for the project
311311
/// - If the head commit of the stack is not found
312312
pub fn merge_base(&self, stack_context: &StackContext) -> Result<git2::Oid> {
313-
let target = stack_context.target();
314-
let repository = stack_context.repository();
315-
let merge_base = repository.merge_base(self.head(&repository.to_gix()?)?, target.sha)?;
313+
let gix_repo = stack_context.repository().to_gix()?;
314+
let target_sha = gix_repo
315+
.find_reference(&stack_context.target().branch.to_string())?
316+
.peel_to_commit()?
317+
.id
318+
.to_git2();
319+
let merge_base = stack_context
320+
.repository()
321+
.merge_base(self.head(&gix_repo)?, target_sha)?;
316322
Ok(merge_base)
317323
}
318324

0 commit comments

Comments
 (0)