@@ -70,6 +70,23 @@ impl Workspace<'_> {
70
70
. all ( |s| s. segments . iter ( ) . all ( |s| !s. is_entrypoint ) )
71
71
}
72
72
73
+ /// Return `true` if the branch with `name` is the workspace target or the targets local tracking branch.
74
+ pub fn is_branch_the_target_or_its_local_tracking_branch (
75
+ & self ,
76
+ name : & gix:: refs:: FullNameRef ,
77
+ ) -> bool {
78
+ let Some ( t) = self . target . as_ref ( ) else {
79
+ return false ;
80
+ } ;
81
+
82
+ t. ref_name . as_ref ( ) == name
83
+ || self
84
+ . graph
85
+ . lookup_sibling_segment ( t. segment_index )
86
+ . and_then ( |local_tracking_segment| local_tracking_segment. ref_name . as_ref ( ) )
87
+ . is_some_and ( |local_tracking_ref| local_tracking_ref. as_ref ( ) == name)
88
+ }
89
+
73
90
/// Return the `commit` at the tip of the workspace itself, and do so by following empty segments along the
74
91
/// first parent until the first commit is found.
75
92
/// This importantly is different from the [`Graph::lookup_entrypoint()`] `commit`, as the entrypoint could be anywhere
@@ -264,6 +281,24 @@ pub enum WorkspaceKind {
264
281
AdHoc ,
265
282
}
266
283
284
+ impl WorkspaceKind {
285
+ /// Return `true` if this workspace has a managed reference, meaning we control certain aspects of it
286
+ /// by means of workspace metadata that is associated with that ref.
287
+ /// If `false`, we are more conservative and may not support all features.
288
+ pub fn has_managed_ref ( & self ) -> bool {
289
+ matches ! (
290
+ self ,
291
+ WorkspaceKind :: Managed { .. } | WorkspaceKind :: ManagedMissingWorkspaceCommit { .. }
292
+ )
293
+ }
294
+
295
+ /// Return `true` if we have a workspace commit, a commit that merges all stacks together.
296
+ /// Implies `has_managed_ref() == true`.
297
+ pub fn has_managed_commit ( & self ) -> bool {
298
+ matches ! ( self , WorkspaceKind :: Managed { .. } )
299
+ }
300
+ }
301
+
267
302
impl WorkspaceKind {
268
303
fn managed ( ref_name : & Option < gix:: refs:: FullName > ) -> anyhow:: Result < Self > {
269
304
Ok ( WorkspaceKind :: Managed {
@@ -279,7 +314,7 @@ impl WorkspaceKind {
279
314
#[ derive( Debug , Clone ) ]
280
315
pub struct Target {
281
316
/// The name of the target branch, i.e. the branch that all [Stacks](Stack) want to get merged into.
282
- /// Typically, this is `origin/main`.
317
+ /// Typically, this is `refs/remotes/ origin/main`.
283
318
pub ref_name : gix:: refs:: FullName ,
284
319
/// The index to the respective segment in the graph.
285
320
pub segment_index : SegmentIndex ,
@@ -438,7 +473,7 @@ impl Graph {
438
473
lower_bound : None ,
439
474
} ;
440
475
441
- let ws_lower_bound = if ws. has_managed_ref ( ) {
476
+ let ws_lower_bound = if ws. kind . has_managed_ref ( ) {
442
477
self . compute_lowest_base ( ws. id , ws. target . as_ref ( ) , self . extra_target )
443
478
. or_else ( || {
444
479
// target not available? Try the base of the workspace itself
@@ -501,7 +536,7 @@ impl Graph {
501
536
* lower_bound_segment_id = None ;
502
537
}
503
538
504
- if ws. has_managed_ref ( ) && self [ ws. id ] . commits . is_empty ( ) {
539
+ if ws. kind . has_managed_ref ( ) && self [ ws. id ] . commits . is_empty ( ) {
505
540
ws. kind = WorkspaceKind :: ManagedMissingWorkspaceCommit {
506
541
ref_name : ws_tip_segment
507
542
. ref_name
@@ -516,7 +551,7 @@ impl Graph {
516
551
. is_some_and ( |rn| rn. as_bstr ( ) . starts_with_str ( "refs/heads/gitbutler/" ) )
517
552
}
518
553
519
- if ws. has_managed_ref ( ) {
554
+ if ws. kind . has_managed_ref ( ) {
520
555
let ( lowest_base, lowest_base_sidx) =
521
556
ws_lower_bound. map_or ( ( None , None ) , |( base, sidx) | ( Some ( base) , Some ( sidx) ) ) ;
522
557
for stack_top_sidx in self
@@ -1070,15 +1105,6 @@ impl Workspace<'_> {
1070
1105
1071
1106
/// Query
1072
1107
impl < ' graph > Workspace < ' graph > {
1073
- /// Return `true` if this workspace is managed, meaning we control certain aspects of it.
1074
- /// If `false`, we are more conservative and may not support all features.
1075
- pub fn has_managed_ref ( & self ) -> bool {
1076
- matches ! (
1077
- self . kind,
1078
- WorkspaceKind :: Managed { .. } | WorkspaceKind :: ManagedMissingWorkspaceCommit { .. }
1079
- )
1080
- }
1081
-
1082
1108
/// Return `true` if the workspace has workspace metadata associated with it.
1083
1109
/// This is relevant when creating references for example.
1084
1110
pub fn has_metadata ( & self ) -> bool {
0 commit comments