@@ -48,14 +48,14 @@ pub(super) mod function {
4848 ///
4949 /// Returns the in memory update [outcome](Outcome) that can then used for materialisation.
5050 pub fn tear_off_branch < ' ws , ' meta , M : RefMetadata > (
51- mut editor : Editor < ' ws , ' meta , M > ,
51+ editor : Editor < ' ws , ' meta , M > ,
5252 subject_branch_name : & FullNameRef ,
5353 stack_id_override : Option < StackId > ,
5454 ) -> anyhow:: Result < Outcome < ' ws , ' meta , M > > {
55- let Some ( source ) = editor
56- . workspace
57- . find_segment_and_stack_by_refname ( subject_branch_name )
58- else {
55+ let sucessful_rebase = editor. rebase ( ) ? ;
56+ let workspace = sucessful_rebase . overlayed_graph ( ) ? . into_workspace ( ) ? ;
57+ let mut editor = sucessful_rebase . into_editor ( ) ;
58+ let Some ( source ) = workspace . find_segment_and_stack_by_refname ( subject_branch_name ) else {
5959 bail ! (
6060 "Couldn't find branch to move in workspace with reference name: {subject_branch_name}"
6161 ) ;
@@ -64,7 +64,7 @@ pub(super) mod function {
6464 // We're currently stopping the move branch operations imperatively at this stage, in order to
6565 // reduce the scope of this first iteration of moving the branches.
6666 // TODO: Enable and test that we can move branches in any kind of workspace.
67- match & editor . workspace . kind {
67+ match & workspace. kind {
6868 WorkspaceKind :: Managed { .. } => { }
6969 WorkspaceKind :: ManagedMissingWorkspaceCommit { .. } => {
7070 bail ! ( "Moving branches currently need a workspace commit" )
@@ -74,7 +74,7 @@ pub(super) mod function {
7474 }
7575 } ;
7676
77- let mut ws_meta = editor . workspace . metadata . clone ( ) ;
77+ let mut ws_meta = workspace. metadata . clone ( ) ;
7878
7979 let ( source_stack, subject_segment) = source;
8080
@@ -86,17 +86,16 @@ pub(super) mod function {
8686 } ) ;
8787 }
8888
89- let Some ( workspace_head) = editor . workspace . tip_commit ( ) . map ( |commit| commit. id ) else {
89+ let Some ( workspace_head) = workspace. tip_commit ( ) . map ( |commit| commit. id ) else {
9090 bail ! ( "Couldn't find workspace head." )
9191 } ;
9292 let head_selector = editor
9393 . select_commit ( workspace_head)
9494 . context ( "Failed to find the workspace head in the graph." ) ?;
9595
96- let Some ( lower_bound_ref) = editor
97- . workspace
96+ let Some ( lower_bound_ref) = workspace
9897 . lower_bound_segment_id
99- . map ( |segment_id| & editor . workspace . graph [ segment_id] )
98+ . map ( |segment_id| & workspace. graph [ segment_id] )
10099 . and_then ( |segment| segment. ref_name ( ) )
101100 else {
102101 bail ! ( "Tearing off a branch requires a workspace common base" ) ;
@@ -107,7 +106,13 @@ pub(super) mod function {
107106 . context ( "Failed to find target reference in graph." ) ?;
108107
109108 let ( subject_delimiter, children_to_disconnect, parents_to_disconnect) =
110- get_disconnect_parameters ( & editor, source_stack, subject_segment, workspace_head) ?;
109+ get_disconnect_parameters (
110+ & editor,
111+ & workspace,
112+ source_stack,
113+ subject_segment,
114+ workspace_head,
115+ ) ?;
111116
112117 editor. disconnect_segment_from (
113118 subject_delimiter. clone ( ) ,
@@ -158,24 +163,25 @@ pub(super) mod function {
158163 ///
159164 /// Returns an [outcome](Outcome) for potential materialisation.
160165 pub fn move_branch < ' ws , ' meta , M : RefMetadata > (
161- mut editor : Editor < ' ws , ' meta , M > ,
166+ editor : Editor < ' ws , ' meta , M > ,
162167 subject_branch_name : & FullNameRef ,
163168 target_branch_name : & FullNameRef ,
164169 ) -> anyhow:: Result < Outcome < ' ws , ' meta , M > > {
165- let ( source, destination) = retrieve_branches_and_containers (
166- editor. workspace ,
167- subject_branch_name,
168- target_branch_name,
169- ) ?;
170+ let sucessful_rebase = editor. rebase ( ) ?;
171+ let workspace = sucessful_rebase. overlayed_graph ( ) ?. into_workspace ( ) ?;
172+ let mut editor = sucessful_rebase. into_editor ( ) ;
173+
174+ let ( source, destination) =
175+ retrieve_branches_and_containers ( & workspace, subject_branch_name, target_branch_name) ?;
170176
171- let Some ( workspace_head) = editor . workspace . tip_commit ( ) . map ( |commit| commit. id ) else {
177+ let Some ( workspace_head) = workspace. tip_commit ( ) . map ( |commit| commit. id ) else {
172178 bail ! ( "Couldn't find workspace head." )
173179 } ;
174180
175181 // We're currently stopping the move branch operations imperatively at this stage, in order to
176182 // reduce the scope of this first iteration of moving the branches.
177183 // TODO: Enable and test that we can move branches in any kind of workspace.
178- match & editor . workspace . kind {
184+ match & workspace. kind {
179185 WorkspaceKind :: Managed { .. } => { }
180186 WorkspaceKind :: ManagedMissingWorkspaceCommit { .. } => {
181187 bail ! ( "Moving branches currently need a workspace commit" )
@@ -185,7 +191,7 @@ pub(super) mod function {
185191 }
186192 } ;
187193
188- let mut ws_meta = editor . workspace . metadata . clone ( ) ;
194+ let mut ws_meta = workspace. metadata . clone ( ) ;
189195
190196 let ( source_stack, subject_segment) = source;
191197 let ( _, target_segment) = destination;
@@ -197,7 +203,13 @@ pub(super) mod function {
197203 . context ( "Failed to find target reference in graph." ) ?;
198204
199205 let ( subject_delimiter, children_to_disconnect, parents_to_disconnect) =
200- get_disconnect_parameters ( & editor, & source_stack, & subject_segment, workspace_head) ?;
206+ get_disconnect_parameters (
207+ & editor,
208+ & workspace,
209+ & source_stack,
210+ & subject_segment,
211+ workspace_head,
212+ ) ?;
201213
202214 let skip_reconnect_step = source_stack. segments . len ( ) == 1 ;
203215 editor. disconnect_segment_from (
@@ -306,6 +318,7 @@ pub(super) mod function {
306318/// as well as the right segment delimiter to move.
307319fn get_disconnect_parameters < ' ws , ' meta , M : RefMetadata > (
308320 editor : & Editor < ' ws , ' meta , M > ,
321+ workspace : & but_graph:: projection:: Workspace ,
309322 source_stack : & Stack ,
310323 subject_segment : & StackSegment ,
311324 workspace_head : gix:: ObjectId ,
@@ -358,7 +371,7 @@ fn get_disconnect_parameters<'ws, 'meta, M: RefMetadata>(
358371 // graph data, and it's probably the target branch, which is not included in the workspace.
359372 let graph_base_segment = subject_segment
360373 . base_segment_id
361- . map ( |segment_idx| & editor . workspace . graph [ segment_idx] ) ;
374+ . map ( |segment_idx| & workspace. graph [ segment_idx] ) ;
362375
363376 let parents_to_disconnect = if let Some ( stack_base_segment) = stack_base_segment {
364377 // Base segment is part of the source stack.
0 commit comments