@@ -8,10 +8,11 @@ use gitbutler_project::Project;
8
8
use gitbutler_oplog:: { OplogExt , entry:: { OperationKind , SnapshotDetails } } ;
9
9
mod amend;
10
10
mod assign;
11
+ mod commits;
11
12
mod move_commit;
12
13
mod squash;
13
- mod undo;
14
14
mod uncommit;
15
+ mod undo;
15
16
16
17
use crate :: id:: CliId ;
17
18
@@ -58,12 +59,20 @@ pub(crate) fn handle(
58
59
uncommit:: file_from_commit ( ctx, path, commit_oid) ?;
59
60
}
60
61
( CliId :: CommittedFile { .. } , CliId :: Branch { .. } ) => {
61
- // Extract file from commit to branch - for now, not implemented
62
- bail ! ( "Extracting files from commits is not yet supported. Use git commands to extract file changes." )
62
+ // Extract file from commit to branch - for now, not implemented
63
+ bail ! (
64
+ "Extracting files from commits is not yet supported. Use git commands to extract file changes."
65
+ )
63
66
}
64
- ( CliId :: CommittedFile { .. } , CliId :: Commit { .. } ) => {
65
- // Move file from one commit to another - for now, not implemented
66
- bail ! ( "Moving files between commits is not yet supported. Use git commands to modify commits." )
67
+ (
68
+ CliId :: CommittedFile {
69
+ path,
70
+ commit_oid : source_id,
71
+ } ,
72
+ CliId :: Commit { oid : target_id } ,
73
+ ) => {
74
+ create_snapshot ( ctx, & project, OperationKind :: FileChanges ) ;
75
+ commits:: commited_file_to_another_commit ( ctx, path, * source_id, * target_id) ?;
67
76
}
68
77
( CliId :: Unassigned , CliId :: UncommittedFile { .. } ) => {
69
78
bail ! ( makes_no_sense_error( & source, & target) )
@@ -74,11 +83,11 @@ pub(crate) fn handle(
74
83
( CliId :: Unassigned , CliId :: Commit { oid } ) => {
75
84
create_snapshot ( ctx, & project, OperationKind :: AmendCommit ) ;
76
85
amend:: assignments_to_commit ( ctx, None , oid) ?;
77
- } ,
86
+ }
78
87
( CliId :: Unassigned , CliId :: Branch { name : to } ) => {
79
88
create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
80
89
assign:: assign_all ( ctx, None , Some ( to) ) ?;
81
- } ,
90
+ }
82
91
( CliId :: Unassigned , CliId :: CommittedFile { .. } ) => {
83
92
bail ! ( makes_no_sense_error( & source, & target) )
84
93
}
@@ -91,15 +100,15 @@ pub(crate) fn handle(
91
100
( CliId :: Commit { oid } , CliId :: Unassigned ) => {
92
101
create_snapshot ( ctx, & project, OperationKind :: UndoCommit ) ;
93
102
undo:: commit ( ctx, oid) ?;
94
- } ,
103
+ }
95
104
( CliId :: Commit { oid : source_oid } , CliId :: Commit { oid : destination } ) => {
96
105
create_snapshot ( ctx, & project, OperationKind :: SquashCommit ) ;
97
106
squash:: commits ( ctx, source_oid, destination) ?;
98
107
}
99
108
( CliId :: Commit { oid } , CliId :: Branch { name } ) => {
100
109
create_snapshot ( ctx, & project, OperationKind :: MoveCommit ) ;
101
110
move_commit:: to_branch ( ctx, oid, name) ?;
102
- } ,
111
+ }
103
112
( CliId :: Branch { .. } , CliId :: UncommittedFile { .. } ) => {
104
113
bail ! ( makes_no_sense_error( & source, & target) )
105
114
}
@@ -140,17 +149,20 @@ fn ids(ctx: &mut CommandContext, source: &str, target: &str) -> anyhow::Result<(
140
149
if target_result. len ( ) != 1 {
141
150
if target_result. is_empty ( ) {
142
151
return Err ( anyhow:: anyhow!(
143
- "Target '{}' not found. If you just performed a Git operation (squash, rebase, etc.), try running 'but status' to refresh the current state." ,
152
+ "Target '{}' not found. If you just performed a Git operation (squash, rebase, etc.), try running 'but status' to refresh the current state." ,
144
153
target
145
154
) ) ;
146
155
} else {
147
- let matches: Vec < String > = target_result. iter ( ) . map ( |id| {
148
- match id {
149
- CliId :: Commit { oid } => format ! ( "{} (commit {})" , id. to_string( ) , & oid. to_string( ) [ ..7 ] ) ,
156
+ let matches: Vec < String > = target_result
157
+ . iter ( )
158
+ . map ( |id| match id {
159
+ CliId :: Commit { oid } => {
160
+ format ! ( "{} (commit {})" , id. to_string( ) , & oid. to_string( ) [ ..7 ] )
161
+ }
150
162
CliId :: Branch { name } => format ! ( "{} (branch '{}')" , id. to_string( ) , name) ,
151
- _ => format ! ( "{} ({})" , id. to_string( ) , id. kind( ) )
152
- }
153
- } ) . collect ( ) ;
163
+ _ => format ! ( "{} ({})" , id. to_string( ) , id. kind( ) ) ,
164
+ } )
165
+ . collect ( ) ;
154
166
return Err ( anyhow:: anyhow!(
155
167
"Target '{}' is ambiguous. Matches: {}. Try using more characters, a longer SHA, or the full branch name to disambiguate." ,
156
168
target,
0 commit comments