@@ -7,10 +7,11 @@ use crate::{
7
7
VirtualBranchesExt ,
8
8
} ;
9
9
use anyhow:: { anyhow, Context , Result } ;
10
+ use but_workspace:: branch:: checkout:: UncommitedWorktreeChanges ;
10
11
use gitbutler_branch:: GITBUTLER_WORKSPACE_REFERENCE ;
11
12
use gitbutler_command_context:: CommandContext ;
12
13
use gitbutler_error:: error:: Marker ;
13
- use gitbutler_oxidize:: ObjectIdExt ;
14
+ use gitbutler_oxidize:: { ObjectIdExt , OidExt } ;
14
15
use gitbutler_project:: FetchResult ;
15
16
use gitbutler_reference:: { Refname , RemoteRefname } ;
16
17
use gitbutler_repo:: {
@@ -53,24 +54,40 @@ pub fn get_base_branch_data(ctx: &CommandContext) -> Result<BaseBranch> {
53
54
Ok ( base)
54
55
}
55
56
57
+ #[ instrument( skip( ctx) , err( Debug ) ) ]
56
58
fn go_back_to_integration ( ctx : & CommandContext , default_target : & Target ) -> Result < BaseBranch > {
57
59
let gix_repo = ctx. gix_repo_for_merging ( ) ?;
58
- let ( mut outcome, conflict_kind) =
59
- but_workspace:: merge_worktree_with_workspace ( ctx, & gix_repo) ?;
60
-
61
- if outcome. has_unresolved_conflicts ( conflict_kind) {
62
- return Err ( anyhow ! ( "Conflicts while going back to gitbutler/workspace" ) )
63
- . context ( Marker :: ProjectConflict ) ;
64
- }
60
+ if ctx. app_settings ( ) . feature_flags . v3 {
61
+ let workspace_commit_to_checkout = but_workspace:: head ( ctx) ?;
62
+ let tree_to_checkout_to_avoid_ref_update = gix_repo
63
+ . find_commit ( workspace_commit_to_checkout. to_gix ( ) ) ?
64
+ . tree_id ( ) ?;
65
+ but_workspace:: branch:: safe_checkout (
66
+ gix_repo. head_id ( ) ?. detach ( ) ,
67
+ tree_to_checkout_to_avoid_ref_update. detach ( ) ,
68
+ & gix_repo,
69
+ but_workspace:: branch:: checkout:: Options {
70
+ uncommitted_changes : UncommitedWorktreeChanges :: KeepAndAbortOnConflict ,
71
+ } ,
72
+ ) ?;
73
+ } else {
74
+ let ( mut outcome, conflict_kind) =
75
+ but_workspace:: merge_worktree_with_workspace ( ctx, & gix_repo) ?;
76
+
77
+ if outcome. has_unresolved_conflicts ( conflict_kind) {
78
+ return Err ( anyhow ! ( "Conflicts while going back to gitbutler/workspace" ) )
79
+ . context ( Marker :: ProjectConflict ) ;
80
+ }
65
81
66
- let final_tree_id = outcome. tree . write ( ) ?. detach ( ) ;
82
+ let final_tree_id = outcome. tree . write ( ) ?. detach ( ) ;
67
83
68
- let repo = ctx. repo ( ) ;
69
- let final_tree = repo. find_tree ( final_tree_id. to_git2 ( ) ) ?;
70
- repo. checkout_tree_builder ( & final_tree)
71
- . force ( )
72
- . checkout ( )
73
- . context ( "failed to checkout tree" ) ?;
84
+ let repo = ctx. repo ( ) ;
85
+ let final_tree = repo. find_tree ( final_tree_id. to_git2 ( ) ) ?;
86
+ repo. checkout_tree_builder ( & final_tree)
87
+ . force ( )
88
+ . checkout ( )
89
+ . context ( "failed to checkout tree" ) ?;
90
+ }
74
91
75
92
let base = target_to_base_branch ( ctx, default_target) ?;
76
93
let vb_state = VirtualBranchesHandle :: new ( ctx. project ( ) . gb_dir ( ) ) ;
0 commit comments