@@ -23,100 +23,105 @@ pub(crate) fn handle(
23
23
) -> anyhow:: Result < ( ) > {
24
24
let project = Project :: from_path ( repo_path) . expect ( "Failed to create project from path" ) ;
25
25
let ctx = & mut CommandContext :: open ( & project, AppSettings :: load_from_default_path_creating ( ) ?) ?;
26
- let ( source , target) = ids ( ctx, source_str, target_str) ?;
26
+ let ( sources , target) = ids ( ctx, source_str, target_str) ?;
27
27
28
- match ( & source, & target) {
29
- ( CliId :: UncommittedFile { .. } , CliId :: UncommittedFile { .. } ) => {
30
- bail ! ( makes_no_sense_error( & source, & target) )
31
- }
32
- ( CliId :: UncommittedFile { path, .. } , CliId :: Unassigned ) => {
33
- create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
34
- assign:: unassign_file ( ctx, path)
35
- }
36
- ( CliId :: UncommittedFile { path, assignment } , CliId :: Commit { oid } ) => {
37
- create_snapshot ( ctx, & project, OperationKind :: AmendCommit ) ;
38
- amend:: file_to_commit ( ctx, path, * assignment, oid)
39
- }
40
- ( CliId :: UncommittedFile { path, .. } , CliId :: Branch { name } ) => {
41
- create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
42
- assign:: assign_file_to_branch ( ctx, path, name)
43
- }
44
- ( CliId :: UncommittedFile { .. } , CliId :: CommittedFile { .. } ) => {
45
- bail ! ( makes_no_sense_error( & source, & target) )
46
- }
47
- // CommittedFile operations
48
- ( CliId :: CommittedFile { .. } , CliId :: UncommittedFile { .. } ) => {
49
- bail ! ( makes_no_sense_error( & source, & target) )
50
- }
51
- ( CliId :: CommittedFile { .. } , CliId :: CommittedFile { .. } ) => {
52
- bail ! ( makes_no_sense_error( & source, & target) )
53
- }
54
- ( CliId :: CommittedFile { path, commit_oid } , CliId :: Unassigned ) => {
55
- create_snapshot ( ctx, & project, OperationKind :: FileChanges ) ;
56
- uncommit:: file_from_commit ( ctx, path, commit_oid)
57
- }
58
- ( CliId :: CommittedFile { .. } , CliId :: Branch { .. } ) => {
59
- // Extract file from commit to branch - for now, not implemented
60
- bail ! ( "Extracting files from commits is not yet supported. Use git commands to extract file changes." )
61
- }
62
- ( CliId :: CommittedFile { .. } , CliId :: Commit { .. } ) => {
63
- // Move file from one commit to another - for now, not implemented
64
- bail ! ( "Moving files between commits is not yet supported. Use git commands to modify commits." )
65
- }
66
- ( CliId :: Unassigned , CliId :: UncommittedFile { .. } ) => {
67
- bail ! ( makes_no_sense_error( & source, & target) )
68
- }
69
- ( CliId :: Unassigned , CliId :: Unassigned ) => {
70
- bail ! ( makes_no_sense_error( & source, & target) )
71
- }
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
- } ,
80
- ( CliId :: Unassigned , CliId :: CommittedFile { .. } ) => {
81
- bail ! ( makes_no_sense_error( & source, & target) )
82
- }
83
- ( CliId :: Commit { .. } , CliId :: UncommittedFile { .. } ) => {
84
- bail ! ( makes_no_sense_error( & source, & target) )
85
- }
86
- ( CliId :: Commit { .. } , CliId :: CommittedFile { .. } ) => {
87
- bail ! ( makes_no_sense_error( & source, & target) )
88
- }
89
- ( CliId :: Commit { oid } , CliId :: Unassigned ) => {
90
- create_snapshot ( ctx, & project, OperationKind :: UndoCommit ) ;
91
- undo:: commit ( ctx, oid)
92
- } ,
93
- ( CliId :: Commit { oid : source } , CliId :: Commit { oid : destination } ) => {
94
- create_snapshot ( ctx, & project, OperationKind :: SquashCommit ) ;
95
- squash:: commits ( ctx, source, destination)
96
- }
97
- ( CliId :: Commit { oid } , CliId :: Branch { name } ) => {
98
- create_snapshot ( ctx, & project, OperationKind :: MoveCommit ) ;
99
- move_commit:: to_branch ( ctx, oid, name)
100
- } ,
101
- ( CliId :: Branch { .. } , CliId :: UncommittedFile { .. } ) => {
102
- bail ! ( makes_no_sense_error( & source, & target) )
103
- }
104
- ( CliId :: Branch { .. } , CliId :: CommittedFile { .. } ) => {
105
- bail ! ( makes_no_sense_error( & source, & target) )
106
- }
107
- ( CliId :: Branch { name : from } , CliId :: Unassigned ) => {
108
- create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
109
- assign:: assign_all ( ctx, Some ( from) , None )
110
- }
111
- ( CliId :: Branch { name } , CliId :: Commit { oid } ) => {
112
- create_snapshot ( ctx, & project, OperationKind :: AmendCommit ) ;
113
- amend:: assignments_to_commit ( ctx, Some ( name) , oid)
114
- }
115
- ( CliId :: Branch { name : from } , CliId :: Branch { name : to } ) => {
116
- create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
117
- assign:: assign_all ( ctx, Some ( from) , Some ( to) )
28
+ // Process each source with the target
29
+ for source in sources {
30
+ match ( & source, & target) {
31
+ ( CliId :: UncommittedFile { .. } , CliId :: UncommittedFile { .. } ) => {
32
+ bail ! ( makes_no_sense_error( & source, & target) )
33
+ }
34
+ ( CliId :: UncommittedFile { path, .. } , CliId :: Unassigned ) => {
35
+ create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
36
+ assign:: unassign_file ( ctx, path) ?;
37
+ }
38
+ ( CliId :: UncommittedFile { path, assignment } , CliId :: Commit { oid } ) => {
39
+ create_snapshot ( ctx, & project, OperationKind :: AmendCommit ) ;
40
+ amend:: file_to_commit ( ctx, path, * assignment, oid) ?;
41
+ }
42
+ ( CliId :: UncommittedFile { path, .. } , CliId :: Branch { name } ) => {
43
+ create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
44
+ assign:: assign_file_to_branch ( ctx, path, name) ?;
45
+ }
46
+ ( CliId :: UncommittedFile { .. } , CliId :: CommittedFile { .. } ) => {
47
+ bail ! ( makes_no_sense_error( & source, & target) )
48
+ }
49
+ // CommittedFile operations
50
+ ( CliId :: CommittedFile { .. } , CliId :: UncommittedFile { .. } ) => {
51
+ bail ! ( makes_no_sense_error( & source, & target) )
52
+ }
53
+ ( CliId :: CommittedFile { .. } , CliId :: CommittedFile { .. } ) => {
54
+ bail ! ( makes_no_sense_error( & source, & target) )
55
+ }
56
+ ( CliId :: CommittedFile { path, commit_oid } , CliId :: Unassigned ) => {
57
+ create_snapshot ( ctx, & project, OperationKind :: FileChanges ) ;
58
+ uncommit:: file_from_commit ( ctx, path, commit_oid) ?;
59
+ }
60
+ ( 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." )
63
+ }
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 :: Unassigned , CliId :: UncommittedFile { .. } ) => {
69
+ bail ! ( makes_no_sense_error( & source, & target) )
70
+ }
71
+ ( CliId :: Unassigned , CliId :: Unassigned ) => {
72
+ bail ! ( makes_no_sense_error( & source, & target) )
73
+ }
74
+ ( CliId :: Unassigned , CliId :: Commit { oid } ) => {
75
+ create_snapshot ( ctx, & project, OperationKind :: AmendCommit ) ;
76
+ amend:: assignments_to_commit ( ctx, None , oid) ?;
77
+ } ,
78
+ ( CliId :: Unassigned , CliId :: Branch { name : to } ) => {
79
+ create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
80
+ assign:: assign_all ( ctx, None , Some ( to) ) ?;
81
+ } ,
82
+ ( CliId :: Unassigned , CliId :: CommittedFile { .. } ) => {
83
+ bail ! ( makes_no_sense_error( & source, & target) )
84
+ }
85
+ ( CliId :: Commit { .. } , CliId :: UncommittedFile { .. } ) => {
86
+ bail ! ( makes_no_sense_error( & source, & target) )
87
+ }
88
+ ( CliId :: Commit { .. } , CliId :: CommittedFile { .. } ) => {
89
+ bail ! ( makes_no_sense_error( & source, & target) )
90
+ }
91
+ ( CliId :: Commit { oid } , CliId :: Unassigned ) => {
92
+ create_snapshot ( ctx, & project, OperationKind :: UndoCommit ) ;
93
+ undo:: commit ( ctx, oid) ?;
94
+ } ,
95
+ ( CliId :: Commit { oid : source_oid } , CliId :: Commit { oid : destination } ) => {
96
+ create_snapshot ( ctx, & project, OperationKind :: SquashCommit ) ;
97
+ squash:: commits ( ctx, source_oid, destination) ?;
98
+ }
99
+ ( CliId :: Commit { oid } , CliId :: Branch { name } ) => {
100
+ create_snapshot ( ctx, & project, OperationKind :: MoveCommit ) ;
101
+ move_commit:: to_branch ( ctx, oid, name) ?;
102
+ } ,
103
+ ( CliId :: Branch { .. } , CliId :: UncommittedFile { .. } ) => {
104
+ bail ! ( makes_no_sense_error( & source, & target) )
105
+ }
106
+ ( CliId :: Branch { .. } , CliId :: CommittedFile { .. } ) => {
107
+ bail ! ( makes_no_sense_error( & source, & target) )
108
+ }
109
+ ( CliId :: Branch { name : from } , CliId :: Unassigned ) => {
110
+ create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
111
+ assign:: assign_all ( ctx, Some ( from) , None ) ?;
112
+ }
113
+ ( CliId :: Branch { name } , CliId :: Commit { oid } ) => {
114
+ create_snapshot ( ctx, & project, OperationKind :: AmendCommit ) ;
115
+ amend:: assignments_to_commit ( ctx, Some ( name) , oid) ?;
116
+ }
117
+ ( CliId :: Branch { name : from } , CliId :: Branch { name : to } ) => {
118
+ create_snapshot ( ctx, & project, OperationKind :: MoveHunk ) ;
119
+ assign:: assign_all ( ctx, Some ( from) , Some ( to) ) ?;
120
+ }
118
121
}
119
122
}
123
+
124
+ Ok ( ( ) )
120
125
}
121
126
122
127
fn makes_no_sense_error ( source : & CliId , target : & CliId ) -> String {
0 commit comments