From 0ebb6f6036f78f67051630fa6eb45591515a9273 Mon Sep 17 00:00:00 2001 From: Kiril Videlov Date: Tue, 5 Nov 2024 14:08:52 +0100 Subject: [PATCH] Expose `stackBranches` on VirtualBranchReference in the UI To be used for rendering the updated design that shows the top-of-stack branch --- apps/desktop/src/lib/branches/branchListing.ts | 5 +++++ crates/gitbutler-branch-actions/src/branch.rs | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/apps/desktop/src/lib/branches/branchListing.ts b/apps/desktop/src/lib/branches/branchListing.ts index 2a293cf3d..ed8083afc 100644 --- a/apps/desktop/src/lib/branches/branchListing.ts +++ b/apps/desktop/src/lib/branches/branchListing.ts @@ -328,6 +328,11 @@ export class VirtualBranchReference { id!: string; /** Determines if the virtual branch is applied in the workspace */ inWorkspace!: boolean; + /** + List of branch names that are part of the stack + Ordered from newest to oldest (the most recent branch is first in the list) + */ + stackBranches!: string[]; } /** Represents a "commit author" or "signature", based on the data from ther git history */ diff --git a/crates/gitbutler-branch-actions/src/branch.rs b/crates/gitbutler-branch-actions/src/branch.rs index 15d300036..9783aa945 100644 --- a/crates/gitbutler-branch-actions/src/branch.rs +++ b/crates/gitbutler-branch-actions/src/branch.rs @@ -16,6 +16,7 @@ use gitbutler_stack::{Stack as GitButlerBranch, StackId, Target}; use gix::object::tree::diff::Action; use gix::prelude::{ObjectIdExt, TreeDiffChangeExt}; use gix::reference::Category; +use itertools::Itertools; use serde::{Deserialize, Serialize}; use std::borrow::Cow; use std::collections::BTreeSet; @@ -241,10 +242,16 @@ fn branch_group_to_branch( } // Virtual branch associated with this branch - let virtual_branch_reference = virtual_branch.map(|branch| VirtualBranchReference { - given_name: branch.name.clone(), - id: branch.id, - in_workspace: branch.in_workspace, + let virtual_branch_reference = virtual_branch.map(|stack| VirtualBranchReference { + given_name: stack.name.clone(), + id: stack.id, + in_workspace: stack.in_workspace, + stack_branches: stack + .branches() + .iter() + .rev() + .map(|b| b.name.clone()) + .collect_vec(), }); let mut remotes: Vec> = Vec::new(); @@ -448,6 +455,9 @@ pub struct VirtualBranchReference { pub id: StackId, /// Determines if the virtual branch is applied in the workspace pub in_workspace: bool, + /// List of branches that are part of the stack + /// Ordered from newest to oldest (the most recent branch is first in the list) + pub stack_branches: Vec, } /// Takes a list of `branch_names` (the given name, as returned by `BranchListing`) and returns