@@ -25,7 +25,7 @@ use gitbutler_project::access::WorktreeWritePermission;
2525use gitbutler_reference:: { normalize_branch_name, Refname , RemoteRefname } ;
2626use gitbutler_repo:: {
2727 rebase:: { cherry_rebase, cherry_rebase_group} ,
28- LogUntil , RepositoryExt ,
28+ GixRepositoryExt , LogUntil , RepositoryExt ,
2929} ;
3030use gitbutler_repo_actions:: RepoActionsExt ;
3131use gitbutler_stack:: {
@@ -180,25 +180,37 @@ pub fn unapply_ownership(
180180 . find_commit ( workspace_commit_id)
181181 . context ( "failed to find target commit" ) ?;
182182
183- let base_tree = target_commit. tree ( ) . context ( "failed to get target tree" ) ?;
184- let final_tree = applied_statuses. into_iter ( ) . fold (
185- target_commit. tree ( ) . context ( "failed to get target tree" ) ,
186- |final_tree, status| {
187- let final_tree = final_tree?;
183+ let base_tree_id = git2_to_gix_object_id ( target_commit. tree_id ( ) ) ;
184+ let gix_repo = ctx. gix_repository_for_merging ( ) ?;
185+ let ( merge_options_fail_fast, conflict_kind) = gix_repo. merge_options_fail_fast ( ) ?;
186+ let final_tree_id = applied_statuses. into_iter ( ) . try_fold (
187+ git2_to_gix_object_id ( target_commit. tree_id ( ) ) ,
188+ |final_tree_id, status| -> Result < _ > {
188189 let files = status
189190 . 1
190191 . into_iter ( )
191192 . map ( |file| ( file. path , file. hunks ) )
192193 . collect :: < Vec < ( PathBuf , Vec < VirtualBranchHunk > ) > > ( ) ;
193- let tree_oid = gitbutler_diff:: write:: hunks_onto_oid ( ctx, workspace_commit_id, files) ?;
194- let branch_tree = repo. find_tree ( tree_oid) ?;
195- let mut result = repo. merge_trees ( & base_tree, & final_tree, & branch_tree, None ) ?;
196- let final_tree_oid = result. write_tree_to ( ctx. repository ( ) ) ?;
197- repo. find_tree ( final_tree_oid)
198- . context ( "failed to find tree" )
194+ let branch_tree_id =
195+ gitbutler_diff:: write:: hunks_onto_oid ( ctx, workspace_commit_id, files) ?;
196+ let mut merge = gix_repo. merge_trees (
197+ base_tree_id,
198+ final_tree_id,
199+ git2_to_gix_object_id ( branch_tree_id) ,
200+ gix_repo. default_merge_labels ( ) ,
201+ merge_options_fail_fast. clone ( ) ,
202+ ) ?;
203+ if merge. has_unresolved_conflicts ( conflict_kind) {
204+ bail ! ( "Tree has conflicts after merge" )
205+ }
206+ merge
207+ . tree
208+ . write ( |tree| gix_repo. write ( tree) )
209+ . map_err ( |err| anyhow ! ( "Could not write merged tree: {err}" ) )
199210 } ,
200211 ) ?;
201212
213+ let final_tree = repo. find_tree ( gix_to_git2_oid ( final_tree_id) ) ?;
202214 let final_tree_oid = gitbutler_diff:: write:: hunks_onto_tree ( ctx, & final_tree, diff, true ) ?;
203215 let final_tree = repo
204216 . find_tree ( final_tree_oid)
@@ -1035,9 +1047,7 @@ impl IsCommitIntegrated<'_, '_, '_> {
10351047 }
10361048
10371049 // try to merge our tree into the upstream tree
1038- let mut merge_options = self . gix_repo . tree_merge_options ( ) ?;
1039- let conflict_kind = gix:: merge:: tree:: UnresolvedConflict :: Renames ;
1040- merge_options. fail_on_conflict = Some ( conflict_kind) ;
1050+ let ( merge_options, conflict_kind) = self . gix_repo . merge_options_fail_fast ( ) ?;
10411051 let mut merge_output = self
10421052 . gix_repo
10431053 . merge_trees (
0 commit comments