@@ -71,27 +71,43 @@ pub(crate) fn create_branch(
7171            // Find the target stack and get its current head commit 
7272            let  stacks = crate :: log:: stacks ( & ctx) ?; 
7373            let  target_stack = stacks. iter ( ) . find ( |s| { 
74-                 s. heads . iter ( ) . any ( |head| head. name . to_string ( )  == target_branch_name) 
74+                 s. heads 
75+                     . iter ( ) 
76+                     . any ( |head| head. name . to_string ( )  == target_branch_name) 
7577            } ) ; 
76-              
78+ 
7779            let  target_stack = match  target_stack { 
7880                Some ( s)  => s, 
79-                 None  => return  Err ( anyhow:: anyhow!( "No stack found for branch '{}'" ,  target_branch_name) ) , 
81+                 None  => { 
82+                     return  Err ( anyhow:: anyhow!( 
83+                         "No stack found for branch '{}'" , 
84+                         target_branch_name
85+                     ) ) ; 
86+                 } 
8087            } ; 
81-             
82-             let  target_stack_id = target_stack. id . ok_or_else ( || anyhow:: anyhow!( "Target stack has no ID" ) ) ?; 
83-             
88+ 
89+             let  target_stack_id = target_stack
90+                 . id 
91+                 . ok_or_else ( || anyhow:: anyhow!( "Target stack has no ID" ) ) ?; 
92+ 
8493            // Get the stack details to find the head commit 
8594            let  target_stack_details = crate :: log:: stack_details ( & ctx,  target_stack_id) ?; 
8695            if  target_stack_details. branch_details . is_empty ( )  { 
8796                return  Err ( anyhow:: anyhow!( "Target stack has no branch details" ) ) ; 
8897            } 
89-              
98+ 
9099            // Find the target branch in the stack details 
91-             let  target_branch_details = target_stack_details. branch_details . iter ( ) . find ( |b| 
92-                 b. name  == target_branch_name
93-             ) . ok_or_else ( || anyhow:: anyhow!( "Target branch '{}' not found in stack details" ,  target_branch_name) ) ?; 
94-             
100+             let  target_branch_details = target_stack_details
101+                 . branch_details 
102+                 . iter ( ) 
103+                 . find ( |b| b. name  == target_branch_name) 
104+                 . ok_or_else ( || { 
105+                     anyhow:: anyhow!( 
106+                         "Target branch '{}' not found in stack details" , 
107+                         target_branch_name
108+                     ) 
109+                 } ) ?; 
110+ 
95111            // Get the head commit of the target branch 
96112            let  target_head_oid = if  !target_branch_details. commits . is_empty ( )  { 
97113                // Use the last local commit 
@@ -100,10 +116,13 @@ pub(crate) fn create_branch(
100116                // If no local commits, use the last upstream commit 
101117                target_branch_details. upstream_commits . last ( ) . unwrap ( ) . id 
102118            }  else  { 
103-                 return  Err ( anyhow:: anyhow!( "Target branch '{}' has no commits" ,  target_branch_name) ) ; 
119+                 return  Err ( anyhow:: anyhow!( 
120+                     "Target branch '{}' has no commits" , 
121+                     target_branch_name
122+                 ) ) ; 
104123            } ; 
105-              
106-             // Create a new virtual branch   
124+ 
125+             // Create a new virtual branch 
107126            let  mut  guard = project. exclusive_worktree_access ( ) ; 
108127            let  create_request = BranchCreateRequest  { 
109128                name :  Some ( branch_name. to_string ( ) ) , 
@@ -112,12 +131,13 @@ pub(crate) fn create_branch(
112131                selected_for_changes :  None , 
113132            } ; 
114133
115-             let  new_stack_id = create_virtual_branch ( & ctx,  & create_request,  guard. write_permission ( ) ) ?; 
116-             
134+             let  new_stack_id =
135+                 create_virtual_branch ( & ctx,  & create_request,  guard. write_permission ( ) ) ?; 
136+ 
117137            // Now set up the new branch to start from the target branch's head 
118138            let  vb_state = VirtualBranchesHandle :: new ( ctx. project ( ) . gb_dir ( ) ) ; 
119139            let  mut  new_stack = vb_state. get_stack ( new_stack_id. id ) ?; 
120-              
140+ 
121141            // Set the head of the new stack to be the target branch's head 
122142            // This creates the stacking relationship 
123143            let  gix_repo = ctx. repo ( ) . to_gix ( ) ?; 
@@ -158,38 +178,35 @@ pub(crate) fn create_branch(
158178    Ok ( ( ) ) 
159179} 
160180
161- pub ( crate )  fn  unapply_branch ( 
162-     repo_path :  & Path , 
163-     _json :  bool , 
164-     branch_id :  & str , 
165- )  -> anyhow:: Result < ( ) >  { 
181+ pub ( crate )  fn  unapply_branch ( repo_path :  & Path ,  _json :  bool ,  branch_id :  & str )  -> anyhow:: Result < ( ) >  { 
166182    let  project = Project :: from_path ( repo_path) ?; 
167183    let  mut  ctx = CommandContext :: open ( & project,  AppSettings :: load_from_default_path_creating ( ) ?) ?; 
168-      
184+ 
169185    // Try to resolve the branch ID 
170186    let  cli_ids = CliId :: from_str ( & mut  ctx,  branch_id) ?; 
171-      
187+ 
172188    if  cli_ids. is_empty ( )  { 
173189        return  Err ( anyhow:: anyhow!( 
174190            "Branch '{}' not found. Try using a branch CLI ID or full branch name." , 
175191            branch_id
176192        ) ) ; 
177193    } 
178-      
194+ 
179195    if  cli_ids. len ( )  > 1  { 
180-         let  matches:  Vec < String >  = cli_ids. iter ( ) . map ( |id| { 
181-             match  id { 
196+         let  matches:  Vec < String >  = cli_ids
197+             . iter ( ) 
198+             . map ( |id| match  id { 
182199                CliId :: Branch  {  name }  => format ! ( "{} (branch '{}')" ,  id. to_string( ) ,  name) , 
183-                 _ => format ! ( "{} ({})" ,  id. to_string( ) ,  id. kind( ) ) 
184-             } 
185-         } ) . collect ( ) ; 
200+                 _ => format ! ( "{} ({})" ,  id. to_string( ) ,  id. kind( ) ) , 
201+             } ) 
202+              . collect ( ) ; 
186203        return  Err ( anyhow:: anyhow!( 
187204            "Branch '{}' is ambiguous. Matches: {}. Try using more characters or the full branch name." , 
188205            branch_id, 
189206            matches. join( ", " ) 
190207        ) ) ; 
191208    } 
192-      
209+ 
193210    let  cli_id = & cli_ids[ 0 ] ; 
194211    let  stack_id = match  cli_id { 
195212        CliId :: Branch  {  .. }  => { 
@@ -204,7 +221,7 @@ pub(crate) fn unapply_branch(
204221                    } 
205222                } ) 
206223            } ) ; 
207-              
224+ 
208225            match  stack { 
209226                Some ( s)  => s. id . ok_or_else ( || anyhow:: anyhow!( "Stack has no ID" ) ) ?, 
210227                None  => return  Err ( anyhow:: anyhow!( "No stack found for branch '{}'" ,  branch_id) ) , 
@@ -218,25 +235,25 @@ pub(crate) fn unapply_branch(
218235            ) ) ; 
219236        } 
220237    } ; 
221-      
238+ 
222239    let  branch_name = match  cli_id { 
223240        CliId :: Branch  {  name }  => name, 
224241        _ => unreachable ! ( ) , 
225242    } ; 
226-      
243+ 
227244    println ! ( 
228245        "Unapplying branch '{}' ({})" , 
229246        branch_name. yellow( ) . bold( ) , 
230247        branch_id. blue( ) . underline( ) 
231248    ) ; 
232-      
249+ 
233250    unapply_stack ( & ctx,  stack_id,  Vec :: new ( ) ) ?; 
234-      
251+ 
235252    println ! ( 
236253        "{} Branch '{}' unapplied successfully!" , 
237254        "✓" . green( ) . bold( ) , 
238255        branch_name. yellow( ) . bold( ) 
239256    ) ; 
240-      
257+ 
241258    Ok ( ( ) ) 
242259} 
0 commit comments