@@ -5,6 +5,7 @@ use but_settings::AppSettings;
5
5
use colored:: Colorize ;
6
6
use gitbutler_command_context:: CommandContext ;
7
7
use gitbutler_project:: Project ;
8
+ use gitbutler_oplog:: { OplogExt , entry:: { OperationKind , SnapshotDetails } } ;
8
9
mod amend;
9
10
mod assign;
10
11
mod move_commit;
@@ -29,12 +30,15 @@ pub(crate) fn handle(
29
30
bail ! ( makes_no_sense_error( & source, & target) )
30
31
}
31
32
( CliId :: UncommittedFile { path, .. } , CliId :: Unassigned ) => {
33
+ create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
32
34
assign:: unassign_file ( ctx, path)
33
35
}
34
36
( CliId :: UncommittedFile { path, assignment } , CliId :: Commit { oid } ) => {
37
+ create_snapshot ( ctx, & project, OperationKind :: AmendCommit ) ;
35
38
amend:: file_to_commit ( ctx, path, * assignment, oid)
36
39
}
37
40
( CliId :: UncommittedFile { path, .. } , CliId :: Branch { name } ) => {
41
+ create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
38
42
assign:: assign_file_to_branch ( ctx, path, name)
39
43
}
40
44
( CliId :: UncommittedFile { .. } , CliId :: CommittedFile { .. } ) => {
@@ -48,6 +52,7 @@ pub(crate) fn handle(
48
52
bail ! ( makes_no_sense_error( & source, & target) )
49
53
}
50
54
( CliId :: CommittedFile { path, commit_oid } , CliId :: Unassigned ) => {
55
+ create_snapshot ( ctx, & project, OperationKind :: FileChanges ) ;
51
56
uncommit:: file_from_commit ( ctx, path, commit_oid)
52
57
}
53
58
( CliId :: CommittedFile { .. } , CliId :: Branch { .. } ) => {
@@ -64,8 +69,14 @@ pub(crate) fn handle(
64
69
( CliId :: Unassigned , CliId :: Unassigned ) => {
65
70
bail ! ( makes_no_sense_error( & source, & target) )
66
71
}
67
- ( CliId :: Unassigned , CliId :: Commit { oid } ) => amend:: assignments_to_commit ( ctx, None , oid) ,
68
- ( CliId :: Unassigned , CliId :: Branch { name : to } ) => assign:: assign_all ( ctx, None , Some ( to) ) ,
72
+ ( CliId :: Unassigned , CliId :: Commit { oid } ) => {
73
+ create_snapshot ( ctx, & project, OperationKind :: AmendCommit ) ;
74
+ amend:: assignments_to_commit ( ctx, None , oid)
75
+ } ,
76
+ ( CliId :: Unassigned , CliId :: Branch { name : to } ) => {
77
+ create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
78
+ assign:: assign_all ( ctx, None , Some ( to) )
79
+ } ,
69
80
( CliId :: Unassigned , CliId :: CommittedFile { .. } ) => {
70
81
bail ! ( makes_no_sense_error( & source, & target) )
71
82
}
@@ -75,24 +86,34 @@ pub(crate) fn handle(
75
86
( CliId :: Commit { .. } , CliId :: CommittedFile { .. } ) => {
76
87
bail ! ( makes_no_sense_error( & source, & target) )
77
88
}
78
- ( CliId :: Commit { oid } , CliId :: Unassigned ) => undo:: commit ( ctx, oid) ,
89
+ ( CliId :: Commit { oid } , CliId :: Unassigned ) => {
90
+ create_snapshot ( ctx, & project, OperationKind :: UndoCommit ) ;
91
+ undo:: commit ( ctx, oid)
92
+ } ,
79
93
( CliId :: Commit { oid : source } , CliId :: Commit { oid : destination } ) => {
94
+ create_snapshot ( ctx, & project, OperationKind :: SquashCommit ) ;
80
95
squash:: commits ( ctx, source, destination)
81
96
}
82
- ( CliId :: Commit { oid } , CliId :: Branch { name } ) => move_commit:: to_branch ( ctx, oid, name) ,
97
+ ( CliId :: Commit { oid } , CliId :: Branch { name } ) => {
98
+ create_snapshot ( ctx, & project, OperationKind :: MoveCommit ) ;
99
+ move_commit:: to_branch ( ctx, oid, name)
100
+ } ,
83
101
( CliId :: Branch { .. } , CliId :: UncommittedFile { .. } ) => {
84
102
bail ! ( makes_no_sense_error( & source, & target) )
85
103
}
86
104
( CliId :: Branch { .. } , CliId :: CommittedFile { .. } ) => {
87
105
bail ! ( makes_no_sense_error( & source, & target) )
88
106
}
89
107
( CliId :: Branch { name : from } , CliId :: Unassigned ) => {
108
+ create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
90
109
assign:: assign_all ( ctx, Some ( from) , None )
91
110
}
92
111
( CliId :: Branch { name } , CliId :: Commit { oid } ) => {
112
+ create_snapshot ( ctx, & project, OperationKind :: AmendCommit ) ;
93
113
amend:: assignments_to_commit ( ctx, Some ( name) , oid)
94
114
}
95
115
( CliId :: Branch { name : from } , CliId :: Branch { name : to } ) => {
116
+ create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
96
117
assign:: assign_all ( ctx, Some ( from) , Some ( to) )
97
118
}
98
119
}
@@ -155,3 +176,13 @@ fn ids(ctx: &mut CommandContext, source: &str, target: &str) -> anyhow::Result<(
155
176
}
156
177
Ok ( ( source_result[ 0 ] . clone ( ) , target_result[ 0 ] . clone ( ) ) )
157
178
}
179
+
180
+ fn create_snapshot ( ctx : & mut CommandContext , project : & Project , operation : OperationKind ) {
181
+ let mut guard = project. exclusive_worktree_access ( ) ;
182
+ let _snapshot = ctx
183
+ . create_snapshot (
184
+ SnapshotDetails :: new ( operation) ,
185
+ guard. write_permission ( ) ,
186
+ )
187
+ . ok ( ) ; // Ignore errors for snapshot creation
188
+ }
0 commit comments