1- use anyhow:: { bail, Result } ;
1+ use crate :: VirtualBranchesExt as _;
2+ use anyhow:: { anyhow, bail, Result } ;
23use gitbutler_cherry_pick:: RepositoryExt ;
34use gitbutler_command_context:: CommandContext ;
45use gitbutler_commit:: commit_ext:: CommitExt as _;
6+ use gitbutler_oxidize:: { git2_to_gix_object_id, gix_to_git2_oid} ;
57use gitbutler_project:: access:: WorktreeWritePermission ;
68use gitbutler_repo:: rebase:: cherry_rebase_group;
7- use gitbutler_repo:: RepositoryExt as _;
9+ use gitbutler_repo:: { GixRepositoryExt , RepositoryExt as _} ;
810use gitbutler_stack:: Stack ;
9-
10- use crate :: VirtualBranchesExt as _ ;
11+ use gix :: prelude :: Write ;
12+ use tracing :: instrument ;
1113
1214/// Checks out the combined trees of all branches in the workspace.
1315///
1416/// This function will fail if the applied branches conflict with each other.
17+ #[ instrument( level = tracing:: Level :: DEBUG , skip( ctx, _perm) , err( Debug ) ) ]
1518pub fn checkout_branch_trees < ' a > (
1619 ctx : & ' a CommandContext ,
1720 _perm : & mut WorktreeWritePermission ,
@@ -38,23 +41,33 @@ pub fn checkout_branch_trees<'a>(
3841 let merge_base = repository
3942 . merge_base_octopussy ( & branches. iter ( ) . map ( |b| b. head ( ) ) . collect :: < Vec < _ > > ( ) ) ?;
4043
41- let merge_base_tree = repository. find_commit ( merge_base) ?. tree ( ) ?;
42-
43- let mut final_tree = merge_base_tree. clone ( ) ;
44+ let gix_repo = ctx. gix_repository_for_merging ( ) ?;
45+ let merge_base_tree_id =
46+ git2_to_gix_object_id ( repository. find_commit ( merge_base) ?. tree_id ( ) ) ;
47+ let mut final_tree_id = merge_base_tree_id;
4448
49+ let ( merge_options_fail_fast, conflict_kind) = gix_repo. merge_options_fail_fast ( ) ?;
4550 for branch in branches {
46- let theirs = repository. find_tree ( branch. tree ) ?;
47- let mut merge_index =
48- repository. merge_trees ( & merge_base_tree, & final_tree, & theirs, None ) ?;
49-
50- if merge_index. has_conflicts ( ) {
51+ let their_tree_id = git2_to_gix_object_id ( branch. tree ) ;
52+ let mut merge = gix_repo. merge_trees (
53+ merge_base_tree_id,
54+ final_tree_id,
55+ their_tree_id,
56+ gix_repo. default_merge_labels ( ) ,
57+ merge_options_fail_fast. clone ( ) ,
58+ ) ?;
59+
60+ if merge. has_unresolved_conflicts ( conflict_kind) {
5161 bail ! ( "There appears to be conflicts between the virtual branches" ) ;
5262 } ;
5363
54- let tree_oid = merge_index. write_tree_to ( repository) ?;
55- final_tree = repository. find_tree ( tree_oid) ?;
64+ final_tree_id = merge
65+ . tree
66+ . write ( |tree| gix_repo. write ( tree) )
67+ . map_err ( |err| anyhow ! ( "{err}" ) ) ?;
5668 }
5769
70+ let final_tree = repository. find_tree ( gix_to_git2_oid ( final_tree_id) ) ?;
5871 repository
5972 . checkout_tree_builder ( & final_tree)
6073 . force ( )
0 commit comments