@@ -221,7 +221,7 @@ impl Stack {
221221 . ok_or_else ( || anyhow ! ( "Stack is uninitialized" ) ) ?
222222 }
223223
224- pub fn set_head ( & mut self , head : git2:: Oid ) {
224+ fn set_head ( & mut self , head : git2:: Oid ) {
225225 self . head = head;
226226 }
227227
@@ -589,6 +589,25 @@ impl Stack {
589589 gix_repo : & gix:: Repository ,
590590 commit_id : git2:: Oid ,
591591 tree : Option < git2:: Oid > ,
592+ ) -> Result < ( ) > {
593+ self . set_stack_head_inner ( Some ( state) , gix_repo, commit_id, tree)
594+ }
595+
596+ pub fn set_stack_head_without_persisting (
597+ & mut self ,
598+ gix_repo : & gix:: Repository ,
599+ commit_id : git2:: Oid ,
600+ tree : Option < git2:: Oid > ,
601+ ) -> Result < ( ) > {
602+ self . set_stack_head_inner ( None , gix_repo, commit_id, tree)
603+ }
604+
605+ fn set_stack_head_inner (
606+ & mut self ,
607+ state : Option < & VirtualBranchesHandle > ,
608+ gix_repo : & gix:: Repository ,
609+ commit_id : git2:: Oid ,
610+ tree : Option < git2:: Oid > ,
592611 ) -> Result < ( ) > {
593612 self . ensure_initialized ( ) ?;
594613 self . updated_timestamp_ms = gitbutler_time:: time:: now_ms ( ) ;
@@ -598,8 +617,6 @@ impl Stack {
598617 self . tree = tree;
599618 }
600619
601- // let state = branch_state(ctx);
602- // let gix_repo = ctx.gix_repository()?;
603620 let commit = gix_repo. find_commit ( commit_id. to_gix ( ) ) ?;
604621
605622 let head = self
@@ -608,7 +625,10 @@ impl Stack {
608625 . ok_or_else ( || anyhow ! ( "Invalid state: no heads found" ) ) ?;
609626
610627 head. set_head ( commit. id . to_git2 ( ) . into ( ) , gix_repo) ?;
611- state. set_stack ( self . clone ( ) )
628+ if let Some ( state) = state {
629+ state. set_stack ( self . clone ( ) ) ?;
630+ }
631+ Ok ( ( ) )
612632 }
613633
614634 /// Removes any heads that are refering to commits that are no longer between the stack head and the merge base
0 commit comments