feat: Update merge base comparison for branch listing

Improves branch listing accuracy by adjusting the merge base
comparison logic. For virtual branches in the workspace, uses the
default target SHA. For others, uses the head commit of the default
branch's upstream. This change ensures more precise branch
comparisons, especially for virtual branches.
This commit is contained in:
Caleb Owens 2024-08-06 10:24:44 +02:00
parent 8a75a0f40f
commit b36c85b211

View File

@ -430,8 +430,23 @@ pub fn get_branch_listing_details(
.get_default_target()
.context("failed to get default target")?;
let mut enriched_branches = Vec::new();
let default_local_branch =
repo.find_branch(default_target.branch.branch(), git2::BranchType::Local)?;
let default_branch = default_local_branch.upstream()?;
let head_commit = default_branch.get().peel_to_commit()?;
for branch in branches {
if let Ok(base) = repo.merge_base(default_target.sha, branch.head) {
let merge_base_comparison = if let Some(virtual_branch) = branch.virtual_branch {
if virtual_branch.in_workspace {
default_target.sha
} else {
head_commit.id()
}
} else {
head_commit.id()
};
if let Ok(base) = repo.merge_base(merge_base_comparison, branch.head) {
let base_tree = repo.find_commit(base)?.tree()?;
let head_tree = repo.find_commit(branch.head)?.tree()?;
let diff_stats = repo