@@ -1225,10 +1225,41 @@ export class Repository implements Disposable {
1225
1225
}
1226
1226
1227
1227
async add ( resources : Uri [ ] , opts ?: { update ?: boolean } ) : Promise < void > {
1228
- await this . run ( Operation . Add , async ( ) => {
1229
- await this . repository . add ( resources . map ( r => r . fsPath ) , opts ) ;
1230
- this . closeDiffEditors ( [ ] , [ ...resources . map ( r => r . fsPath ) ] ) ;
1231
- } ) ;
1228
+ await this . run (
1229
+ Operation . Add ,
1230
+ async ( ) => {
1231
+ await this . repository . add ( resources . map ( r => r . fsPath ) , opts ) ;
1232
+ this . closeDiffEditors ( [ ] , [ ...resources . map ( r => r . fsPath ) ] ) ;
1233
+ } ,
1234
+ ( ) => {
1235
+ const resourcePaths = resources . map ( r => r . fsPath ) ;
1236
+ const indexGroupResourcePaths = this . indexGroup . resourceStates . map ( r => r . resourceUri . fsPath ) ;
1237
+
1238
+ // Collect added resources
1239
+ const addedResourceStates : Resource [ ] = [ ] ;
1240
+ for ( const resource of [ ...this . mergeGroup . resourceStates , ...this . untrackedGroup . resourceStates , ...this . workingTreeGroup . resourceStates ] ) {
1241
+ if ( resourcePaths . includes ( resource . resourceUri . fsPath ) && ! indexGroupResourcePaths . includes ( resource . resourceUri . fsPath ) ) {
1242
+ addedResourceStates . push ( resource ) ;
1243
+ }
1244
+ }
1245
+
1246
+ // Add new resource(s) to index group
1247
+ const indexGroup = [ ...this . indexGroup . resourceStates , ...addedResourceStates ] ;
1248
+
1249
+ // Remove resource(s) from merge group
1250
+ const mergeGroup = this . mergeGroup . resourceStates
1251
+ . filter ( r => ! resourcePaths . includes ( r . resourceUri . fsPath ) ) ;
1252
+
1253
+ // Remove resource(s) from working group
1254
+ const workingTreeGroup = this . workingTreeGroup . resourceStates
1255
+ . filter ( r => ! resourcePaths . includes ( r . resourceUri . fsPath ) ) ;
1256
+
1257
+ // Remove resource(s) from untracked group
1258
+ const untrackedGroup = this . untrackedGroup . resourceStates
1259
+ . filter ( r => ! resourcePaths . includes ( r . resourceUri . fsPath ) ) ;
1260
+
1261
+ return { indexGroup, mergeGroup, workingTreeGroup, untrackedGroup } ;
1262
+ } ) ;
1232
1263
}
1233
1264
1234
1265
async rm ( resources : Uri [ ] ) : Promise < void > {
@@ -1245,12 +1276,43 @@ export class Repository implements Disposable {
1245
1276
}
1246
1277
1247
1278
async revert ( resources : Uri [ ] ) : Promise < void > {
1248
- await this . run ( Operation . RevertFiles , async ( ) => {
1249
- await this . repository . revert ( 'HEAD' , resources . map ( r => r . fsPath ) ) ;
1250
- this . closeDiffEditors ( [ ...resources . length !== 0 ?
1251
- resources . map ( r => r . fsPath ) :
1252
- this . indexGroup . resourceStates . map ( r => r . resourceUri . fsPath ) ] , [ ] ) ;
1253
- } ) ;
1279
+ await this . run (
1280
+ Operation . RevertFiles ,
1281
+ async ( ) => {
1282
+ await this . repository . revert ( 'HEAD' , resources . map ( r => r . fsPath ) ) ;
1283
+ this . closeDiffEditors ( [ ...resources . length !== 0 ?
1284
+ resources . map ( r => r . fsPath ) :
1285
+ this . indexGroup . resourceStates . map ( r => r . resourceUri . fsPath ) ] , [ ] ) ;
1286
+ } ,
1287
+ ( ) => {
1288
+ const resourcePaths = resources . length === 0 ?
1289
+ this . indexGroup . resourceStates . map ( r => r . resourceUri . fsPath ) : resources . map ( r => r . fsPath ) ;
1290
+
1291
+ // Collect removed resources
1292
+ const trackedResources : Resource [ ] = [ ] ;
1293
+ const untrackedResources : Resource [ ] = [ ] ;
1294
+ for ( const resource of this . indexGroup . resourceStates ) {
1295
+ if ( resourcePaths . includes ( resource . resourceUri . fsPath ) ) {
1296
+ if ( resource . type === Status . INDEX_ADDED ) {
1297
+ untrackedResources . push ( resource ) ;
1298
+ } else {
1299
+ trackedResources . push ( resource ) ;
1300
+ }
1301
+ }
1302
+ }
1303
+
1304
+ // Remove resource(s) from index group
1305
+ const indexGroup = this . indexGroup . resourceStates
1306
+ . filter ( r => ! resourcePaths . includes ( r . resourceUri . fsPath ) ) ;
1307
+
1308
+ // Add resource(s) to working group
1309
+ const workingTreeGroup = [ ...this . workingTreeGroup . resourceStates , ...trackedResources ] ;
1310
+
1311
+ // Add resource(s) to untracked group
1312
+ const untrackedGroup = [ ...this . untrackedGroup . resourceStates , ...untrackedResources ] ;
1313
+
1314
+ return { indexGroup, workingTreeGroup, untrackedGroup } ;
1315
+ } ) ;
1254
1316
}
1255
1317
1256
1318
async commit ( message : string | undefined , opts : CommitOptions = Object . create ( null ) ) : Promise < void > {
0 commit comments