@@ -3213,185 +3213,6 @@ pub fn undo_commit(
3213
3213
Ok ( ( ) )
3214
3214
}
3215
3215
3216
- pub fn cherry_pick (
3217
- project_repository : & project_repository:: Repository ,
3218
- branch_id : BranchId ,
3219
- target_commit_id : git2:: Oid ,
3220
- ) -> Result < Option < git2:: Oid > > {
3221
- project_repository. assure_unconflicted ( ) ?;
3222
-
3223
- let vb_state = project_repository. project ( ) . virtual_branches ( ) ;
3224
-
3225
- let mut branch = vb_state
3226
- . get_branch ( branch_id)
3227
- . context ( "failed to read branch" ) ?;
3228
-
3229
- if !branch. applied {
3230
- // todo?
3231
- bail ! ( "can not cherry pick a branch that is not applied" )
3232
- }
3233
-
3234
- let target_commit = project_repository
3235
- . repo ( )
3236
- . find_commit ( target_commit_id)
3237
- . map_err ( |err| match err {
3238
- err if err. code ( ) == git2:: ErrorCode :: NotFound => {
3239
- anyhow ! ( "commit {target_commit_id} not found " )
3240
- }
3241
- err => err. into ( ) ,
3242
- } ) ?;
3243
-
3244
- let branch_head_commit = project_repository
3245
- . repo ( )
3246
- . find_commit ( branch. head )
3247
- . context ( "failed to find branch tree" ) ?;
3248
-
3249
- let default_target = vb_state. get_default_target ( ) ?;
3250
-
3251
- // if any other branches are applied, unapply them
3252
- let applied_branches = vb_state
3253
- . list_branches ( )
3254
- . context ( "failed to read virtual branches" ) ?
3255
- . into_iter ( )
3256
- . filter ( |b| b. applied )
3257
- . collect :: < Vec < _ > > ( ) ;
3258
-
3259
- let integration_commit_id = get_workspace_head ( & vb_state, project_repository) ?;
3260
-
3261
- let ( applied_statuses, _) = get_applied_status (
3262
- project_repository,
3263
- & integration_commit_id,
3264
- & default_target. sha ,
3265
- applied_branches,
3266
- ) ?;
3267
-
3268
- let branch_files = applied_statuses
3269
- . iter ( )
3270
- . find ( |( b, _) | b. id == branch_id)
3271
- . map ( |( _, f) | f)
3272
- . context ( "branch status not found" ) ?;
3273
-
3274
- // create a wip commit. we'll use it to offload cherrypick conflicts calculation to libgit.
3275
- let wip_commit = {
3276
- let wip_tree_oid = write_tree ( project_repository, & branch. head , branch_files) ?;
3277
- let wip_tree = project_repository
3278
- . repo ( )
3279
- . find_tree ( wip_tree_oid)
3280
- . context ( "failed to find tree" ) ?;
3281
-
3282
- let signature = git2:: Signature :: now ( "GitButler" , "gitbutler@gitbutler.com" )
3283
- . context ( "failed to make gb signature" ) ?;
3284
- let oid = project_repository
3285
- . repo ( )
3286
- . commit_with_signature (
3287
- None ,
3288
- & signature,
3289
- & signature,
3290
- "wip cherry picking commit" ,
3291
- & wip_tree,
3292
- & [ & branch_head_commit] ,
3293
- None ,
3294
- )
3295
- . context ( "failed to commit wip work" ) ?;
3296
- project_repository
3297
- . repo ( )
3298
- . find_commit ( oid)
3299
- . context ( "failed to find wip commit" ) ?
3300
- } ;
3301
-
3302
- let mut cherrypick_index = project_repository
3303
- . repo ( )
3304
- . cherrypick_commit ( & target_commit, & wip_commit, 0 , None )
3305
- . context ( "failed to cherry pick" ) ?;
3306
-
3307
- // unapply other branches
3308
- for other_branch in applied_statuses
3309
- . iter ( )
3310
- . filter ( |( b, _) | b. id != branch. id )
3311
- . map ( |( b, _) | b)
3312
- {
3313
- convert_to_real_branch ( project_repository, other_branch. id , Default :: default ( ) )
3314
- . context ( "failed to unapply branch" ) ?;
3315
- }
3316
-
3317
- let commit_oid = if cherrypick_index. has_conflicts ( ) {
3318
- // checkout the conflicts
3319
- project_repository
3320
- . repo ( )
3321
- . checkout_index_builder ( & mut cherrypick_index)
3322
- . allow_conflicts ( )
3323
- . conflict_style_merge ( )
3324
- . force ( )
3325
- . checkout ( )
3326
- . context ( "failed to checkout conflicts" ) ?;
3327
-
3328
- // mark conflicts
3329
- let conflicts = cherrypick_index
3330
- . conflicts ( )
3331
- . context ( "failed to get conflicts" ) ?;
3332
- let mut merge_conflicts = Vec :: new ( ) ;
3333
- for path in conflicts. flatten ( ) {
3334
- if let Some ( ours) = path. our {
3335
- let path = std:: str:: from_utf8 ( & ours. path )
3336
- . context ( "failed to convert path" ) ?
3337
- . to_string ( ) ;
3338
- merge_conflicts. push ( path) ;
3339
- }
3340
- }
3341
- conflicts:: mark ( project_repository, & merge_conflicts, Some ( branch. head ) ) ?;
3342
-
3343
- None
3344
- } else {
3345
- let merge_tree_oid = cherrypick_index
3346
- . write_tree_to ( project_repository. repo ( ) )
3347
- . context ( "failed to write merge tree" ) ?;
3348
- let merge_tree = project_repository
3349
- . repo ( )
3350
- . find_tree ( merge_tree_oid)
3351
- . context ( "failed to find merge tree" ) ?;
3352
-
3353
- let branch_head_commit = project_repository
3354
- . repo ( )
3355
- . find_commit ( branch. head )
3356
- . context ( "failed to find branch head commit" ) ?;
3357
-
3358
- let change_id = target_commit. change_id ( ) ;
3359
- let commit_oid = project_repository
3360
- . repo ( )
3361
- . commit_with_signature (
3362
- None ,
3363
- & target_commit. author ( ) ,
3364
- & target_commit. committer ( ) ,
3365
- & target_commit. message_bstr ( ) . to_str_lossy ( ) ,
3366
- & merge_tree,
3367
- & [ & branch_head_commit] ,
3368
- change_id. as_deref ( ) ,
3369
- )
3370
- . context ( "failed to create commit" ) ?;
3371
-
3372
- // checkout final_tree into the working directory
3373
- project_repository
3374
- . repo ( )
3375
- . checkout_tree_builder ( & merge_tree)
3376
- . force ( )
3377
- . remove_untracked ( )
3378
- . checkout ( )
3379
- . context ( "failed to checkout final tree" ) ?;
3380
-
3381
- // update branch status
3382
- branch. head = commit_oid;
3383
- branch. updated_timestamp_ms = crate :: time:: now_ms ( ) ;
3384
- vb_state. set_branch ( branch. clone ( ) ) ?;
3385
-
3386
- Some ( commit_oid)
3387
- } ;
3388
-
3389
- super :: integration:: update_gitbutler_integration ( & vb_state, project_repository)
3390
- . context ( "failed to update gitbutler integration" ) ?;
3391
-
3392
- Ok ( commit_oid)
3393
- }
3394
-
3395
3216
/// squashes a commit from a virtual branch into its parent.
3396
3217
pub fn squash (
3397
3218
project_repository : & project_repository:: Repository ,
0 commit comments