@@ -102,56 +102,51 @@ pub fn create_reference(app: &App, params: create_reference::Params) -> Result<(
102102pub fn create_branch ( app : & App , params : CreateBranchParams ) -> Result < ( ) , Error > {
103103 let project = gitbutler_project:: get ( params. project_id ) ?;
104104 let ctx = CommandContext :: open ( & project, app. app_settings . get ( ) ?. clone ( ) ) ?;
105- if app. app_settings . get ( ) ?. feature_flags . ws3 {
106- use ReferencePosition :: Above ;
107- let ( repo, mut meta, graph) = ctx. graph_and_meta_and_repo ( ) ?;
108- let ws = graph. to_workspace ( ) ?;
109- let stack = ws. try_find_stack_by_id ( params. stack_id ) ?;
110- let new_ref = Category :: LocalBranch
111- . to_full_name ( params. request . name . as_str ( ) )
112- . map_err ( anyhow:: Error :: from) ?;
113- if params. request . preceding_head . is_some ( ) {
114- return Err ( anyhow ! (
115- "BUG: cannot have preceding head name set - let's use the new API instead"
116- )
117- . into ( ) ) ;
118- }
105+ use ReferencePosition :: Above ;
106+ let ( repo, mut meta, graph) = ctx. graph_and_meta_and_repo ( ) ?;
107+ let ws = graph. to_workspace ( ) ?;
108+ let stack = ws. try_find_stack_by_id ( params. stack_id ) ?;
109+ let new_ref = Category :: LocalBranch
110+ . to_full_name ( params. request . name . as_str ( ) )
111+ . map_err ( anyhow:: Error :: from) ?;
112+ if params. request . preceding_head . is_some ( ) {
113+ return Err ( anyhow ! (
114+ "BUG: cannot have preceding head name set - let's use the new API instead"
115+ )
116+ . into ( ) ) ;
117+ }
119118
120- let mut guard = project. exclusive_worktree_access ( ) ;
121- ctx. snapshot_create_dependent_branch ( & params. request . name , guard. write_permission ( ) )
122- . ok ( ) ;
123- _ = but_workspace:: branch:: create_reference (
124- new_ref. as_ref ( ) ,
125- {
126- let segment = stack. segments . first ( ) . context ( "BUG: no empty stacks" ) ?;
127- segment
128- . ref_name
129- . as_ref ( )
130- . map ( |rn| ReferenceAnchor :: AtSegment {
131- ref_name : Cow :: Borrowed ( rn. as_ref ( ) ) ,
119+ let mut guard = project. exclusive_worktree_access ( ) ;
120+ ctx. snapshot_create_dependent_branch ( & params. request . name , guard. write_permission ( ) )
121+ . ok ( ) ;
122+ _ = but_workspace:: branch:: create_reference (
123+ new_ref. as_ref ( ) ,
124+ {
125+ let segment = stack. segments . first ( ) . context ( "BUG: no empty stacks" ) ?;
126+ segment
127+ . ref_name
128+ . as_ref ( )
129+ . map ( |rn| ReferenceAnchor :: AtSegment {
130+ ref_name : Cow :: Borrowed ( rn. as_ref ( ) ) ,
131+ position : Above ,
132+ } )
133+ . or_else ( || {
134+ Some ( ReferenceAnchor :: AtCommit {
135+ commit_id : graph. tip_skip_empty ( segment. id ) ?. id ,
132136 position : Above ,
133137 } )
134- . or_else ( || {
135- Some ( ReferenceAnchor :: AtCommit {
136- commit_id : graph. tip_skip_empty ( segment. id ) ?. id ,
137- position : Above ,
138- } )
139- } )
140- . with_context ( || {
141- format ! (
142- "TODO: UI should migrate to new version of `create_branch()` instead,\
138+ } )
139+ . with_context ( || {
140+ format ! (
141+ "TODO: UI should migrate to new version of `create_branch()` instead,\
143142 couldn't handle {params:?}"
144- )
145- } ) ?
146- } ,
147- & repo,
148- & ws,
149- & mut meta,
150- ) ?;
151- } else {
152- // NOTE: locking is built-in here.
153- gitbutler_branch_actions:: stack:: create_branch ( & ctx, params. stack_id , params. request ) ?;
154- }
143+ )
144+ } ) ?
145+ } ,
146+ & repo,
147+ & ws,
148+ & mut meta,
149+ ) ?;
155150 Ok ( ( ) )
156151}
157152
@@ -166,31 +161,27 @@ pub struct RemoveBranchParams {
166161pub fn remove_branch ( app : & App , params : RemoveBranchParams ) -> Result < ( ) , Error > {
167162 let project = gitbutler_project:: get ( params. project_id ) ?;
168163 let ctx = CommandContext :: open ( & project, app. app_settings . get ( ) ?. clone ( ) ) ?;
169- if app. app_settings . get ( ) ?. feature_flags . ws3 {
170- let ( repo, mut meta, graph) = ctx. graph_and_meta_and_repo ( ) ?;
171- let ws = graph. to_workspace ( ) ?;
172- let ref_name = Category :: LocalBranch
173- . to_full_name ( params. branch_name . as_str ( ) )
174- . map_err ( anyhow:: Error :: from) ?;
175- let mut guard = project. exclusive_worktree_access ( ) ;
176- ctx. snapshot_remove_dependent_branch ( & params. branch_name , guard. write_permission ( ) )
177- . ok ( ) ;
178- but_workspace:: branch:: remove_reference (
179- ref_name. as_ref ( ) ,
180- & repo,
181- & ws,
182- & mut meta,
183- but_workspace:: branch:: remove_reference:: Options {
184- avoid_anonymous_stacks : true ,
185- // The UI kind of keeps it, but we can't do that somehow
186- // the object id is null, and stuff breaks. Fine for now.
187- // Delete is delete.
188- keep_metadata : false ,
189- } ,
190- ) ?;
191- } else {
192- gitbutler_branch_actions:: stack:: remove_branch ( & ctx, params. stack_id , params. branch_name ) ?;
193- }
164+ let ( repo, mut meta, graph) = ctx. graph_and_meta_and_repo ( ) ?;
165+ let ws = graph. to_workspace ( ) ?;
166+ let ref_name = Category :: LocalBranch
167+ . to_full_name ( params. branch_name . as_str ( ) )
168+ . map_err ( anyhow:: Error :: from) ?;
169+ let mut guard = project. exclusive_worktree_access ( ) ;
170+ ctx. snapshot_remove_dependent_branch ( & params. branch_name , guard. write_permission ( ) )
171+ . ok ( ) ;
172+ but_workspace:: branch:: remove_reference (
173+ ref_name. as_ref ( ) ,
174+ & repo,
175+ & ws,
176+ & mut meta,
177+ but_workspace:: branch:: remove_reference:: Options {
178+ avoid_anonymous_stacks : true ,
179+ // The UI kind of keeps it, but we can't do that somehow
180+ // the object id is null, and stuff breaks. Fine for now.
181+ // Delete is delete.
182+ keep_metadata : false ,
183+ } ,
184+ ) ?;
194185 Ok ( ( ) )
195186}
196187
0 commit comments