Merge pull request #3910 from gitbutlerapp/check-mergeable-state-of-virtual-branch

feat: Show merge base of virtual branch in commit list
This commit is contained in:
Kiril Videlov 2024-05-30 20:03:18 +02:00 committed by GitHub
commit e908828b3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 10 deletions

View File

@ -23,7 +23,6 @@
$: hasCommits = $branch.commits && $branch.commits.length > 0;
$: headCommit = $branch.commits.at(0);
$: hasUnknownCommits = $unknownCommits.length > 0;
$: baseCommit = $baseBranch.recentCommits.at($baseBranch.recentCommits.length - 1)?.id;
let baseIsUnfolded = false;
</script>
@ -144,7 +143,7 @@
class="base-row__commit-link"
on:click={async () => await goto(`/${project.id}/base`)}
>
{baseCommit ? baseCommit.slice(0, 7) : ''}
{$branch.mergeBase ? $branch.mergeBase.slice(0, 7) : ''}
</button>
</span>
</div>

View File

@ -126,6 +126,8 @@ export class Branch {
updatedAt!: Date;
// Indicates that branch is default target for new changes
selectedForChanges!: boolean;
/// The merge base between the target branch and the virtual branch
mergeBase!: string;
get localCommits() {
return this.commits.filter((c) => c.status == 'local');

View File

@ -71,6 +71,8 @@ pub struct VirtualBranch {
pub updated_at: u128,
pub selected_for_changes: bool,
pub head: git::Oid,
/// The merge base between the target branch and the virtual branch
pub merge_base: git::Oid,
}
#[derive(Debug, PartialEq, Clone, Serialize)]
@ -863,16 +865,12 @@ pub fn list_virtual_branches(
})
.collect::<Result<Vec<_>>>()?;
// if the branch is not applied, check to see if it's mergeable and up to date
let merge_base = repo
.merge_base(default_target.sha, branch.head)
.context("failed to find merge base")?;
let mut base_current = true;
if !branch.applied {
// determine if this branch is up to date with the target/base
let merge_base = repo
.merge_base(default_target.sha, branch.head)
.context("failed to find merge base")?;
if merge_base != default_target.sha {
base_current = false;
}
base_current = merge_base == default_target.sha;
}
let upstream = upstream_branch
@ -918,6 +916,7 @@ pub fn list_virtual_branches(
updated_at: branch.updated_timestamp_ms,
selected_for_changes: branch.selected_for_changes == Some(max_selected_for_changes),
head: branch.head,
merge_base,
};
branches.push(branch);
}