11use std:: { path:: Path , time} ;
22
3- use anyhow:: { anyhow, Context , Result } ;
3+ use crate :: {
4+ conflicts:: RepoConflictsExt ,
5+ hunk:: VirtualBranchHunk ,
6+ integration:: update_workspace_commit,
7+ remote:: { commit_to_remote_commit, RemoteCommit } ,
8+ VirtualBranchesExt ,
9+ } ;
10+ use anyhow:: { anyhow, bail, Context , Result } ;
411use gitbutler_branch:: GITBUTLER_WORKSPACE_REFERENCE ;
512use gitbutler_command_context:: CommandContext ;
613use gitbutler_error:: error:: Marker ;
14+ use gitbutler_oxidize:: { git2_to_gix_object_id, gix_to_git2_oid} ;
715use gitbutler_project:: FetchResult ;
816use gitbutler_reference:: { Refname , RemoteRefname } ;
9- use gitbutler_repo:: { LogUntil , RepositoryExt } ;
17+ use gitbutler_repo:: { GixRepositoryExt , LogUntil , RepositoryExt } ;
1018use gitbutler_repo_actions:: RepoActionsExt ;
1119use gitbutler_stack:: { BranchOwnershipClaims , Stack , Target , VirtualBranchesHandle } ;
1220use serde:: Serialize ;
1321
14- use crate :: {
15- conflicts:: RepoConflictsExt ,
16- hunk:: VirtualBranchHunk ,
17- integration:: update_workspace_commit,
18- remote:: { commit_to_remote_commit, RemoteCommit } ,
19- VirtualBranchesExt ,
20- } ;
21-
2222#[ derive( Debug , Serialize , PartialEq , Clone ) ]
2323#[ serde( rename_all = "camelCase" ) ]
2424pub struct BaseBranch {
@@ -50,8 +50,8 @@ pub(crate) fn get_base_branch_data(ctx: &CommandContext) -> Result<BaseBranch> {
5050}
5151
5252fn go_back_to_integration ( ctx : & CommandContext , default_target : & Target ) -> Result < BaseBranch > {
53- let statuses = ctx
54- . repository ( )
53+ let repo = ctx. repository ( ) ;
54+ let statuses = repo
5555 . statuses ( Some (
5656 git2:: StatusOptions :: new ( )
5757 . show ( git2:: StatusShow :: IndexAndWorkdir )
@@ -67,41 +67,36 @@ fn go_back_to_integration(ctx: &CommandContext, default_target: &Target) -> Resu
6767 . list_branches_in_workspace ( )
6868 . context ( "failed to read virtual branches" ) ?;
6969
70- let target_commit = ctx
71- . repository ( )
70+ let target_commit = repo
7271 . find_commit ( default_target. sha )
7372 . context ( "failed to find target commit" ) ?;
7473
75- let base_tree = target_commit
76- . tree ( )
77- . context ( "failed to get base tree from commit" ) ?;
78- let mut final_tree = target_commit
79- . tree ( )
80- . context ( "failed to get base tree from commit" ) ?;
74+ let base_tree = git2_to_gix_object_id ( target_commit. tree_id ( ) ) ;
75+ let mut final_tree_id = git2_to_gix_object_id ( target_commit. tree_id ( ) ) ;
76+ let gix_repo = ctx. gix_repository_for_merging ( ) ?;
77+ let ( merge_options_fail_fast, conflict_kind) = gix_repo. merge_options_fail_fast ( ) ?;
8178 for branch in & virtual_branches {
8279 // merge this branches tree with our tree
83- let branch_head = ctx
84- . repository ( )
85- . find_commit ( branch. head ( ) )
86- . context ( "failed to find branch head" ) ?;
87- let branch_tree = branch_head
88- . tree ( )
89- . context ( "failed to get branch head tree" ) ?;
90- let mut result = ctx
91- . repository ( )
92- . merge_trees ( & base_tree, & final_tree, & branch_tree, None )
93- . context ( "failed to merge" ) ?;
94- let final_tree_oid = result
95- . write_tree_to ( ctx. repository ( ) )
96- . context ( "failed to write tree" ) ?;
97- final_tree = ctx
98- . repository ( )
99- . find_tree ( final_tree_oid)
100- . context ( "failed to find written tree" ) ?;
80+ let branch_tree_id = git2_to_gix_object_id (
81+ repo. find_commit ( branch. head ( ) )
82+ . context ( "failed to find branch head" ) ?
83+ . tree_id ( ) ,
84+ ) ;
85+ let mut merge = gix_repo. merge_trees (
86+ base_tree,
87+ final_tree_id,
88+ branch_tree_id,
89+ gix_repo. default_merge_labels ( ) ,
90+ merge_options_fail_fast. clone ( ) ,
91+ ) ?;
92+ if merge. has_unresolved_conflicts ( conflict_kind) {
93+ bail ! ( "Merge failed with conflicts" ) ;
94+ }
95+ final_tree_id = merge. tree . write ( ) ?. detach ( ) ;
10196 }
10297
103- ctx . repository ( )
104- . checkout_tree_builder ( & final_tree)
98+ let final_tree = repo . find_tree ( gix_to_git2_oid ( final_tree_id ) ) ? ;
99+ repo . checkout_tree_builder ( & final_tree)
105100 . force ( )
106101 . checkout ( )
107102 . context ( "failed to checkout tree" ) ?;
0 commit comments