@@ -1387,47 +1387,62 @@ export class Repository implements Disposable {
13871387 }
13881388
13891389 async clean ( resources : Uri [ ] ) : Promise < void > {
1390- await this . run ( Operation . Clean , async ( ) => {
1391- const toClean : string [ ] = [ ] ;
1392- const toCheckout : string [ ] = [ ] ;
1393- const submodulesToUpdate : string [ ] = [ ] ;
1394- const resourceStates = [ ...this . workingTreeGroup . resourceStates , ...this . untrackedGroup . resourceStates ] ;
1395-
1396- resources . forEach ( r => {
1397- const fsPath = r . fsPath ;
1398-
1399- for ( const submodule of this . submodules ) {
1400- if ( path . join ( this . root , submodule . path ) === fsPath ) {
1401- submodulesToUpdate . push ( fsPath ) ;
1390+ await this . run (
1391+ Operation . Clean ,
1392+ async ( ) => {
1393+ const toClean : string [ ] = [ ] ;
1394+ const toCheckout : string [ ] = [ ] ;
1395+ const submodulesToUpdate : string [ ] = [ ] ;
1396+ const resourceStates = [ ...this . workingTreeGroup . resourceStates , ...this . untrackedGroup . resourceStates ] ;
1397+
1398+ resources . forEach ( r => {
1399+ const fsPath = r . fsPath ;
1400+
1401+ for ( const submodule of this . submodules ) {
1402+ if ( path . join ( this . root , submodule . path ) === fsPath ) {
1403+ submodulesToUpdate . push ( fsPath ) ;
1404+ return ;
1405+ }
1406+ }
1407+
1408+ const raw = r . toString ( ) ;
1409+ const scmResource = find ( resourceStates , sr => sr . resourceUri . toString ( ) === raw ) ;
1410+
1411+ if ( ! scmResource ) {
14021412 return ;
14031413 }
1404- }
14051414
1406- const raw = r . toString ( ) ;
1407- const scmResource = find ( resourceStates , sr => sr . resourceUri . toString ( ) === raw ) ;
1415+ switch ( scmResource . type ) {
1416+ case Status . UNTRACKED :
1417+ case Status . IGNORED :
1418+ toClean . push ( fsPath ) ;
1419+ break ;
14081420
1409- if ( ! scmResource ) {
1410- return ;
1411- }
1421+ default :
1422+ toCheckout . push ( fsPath ) ;
1423+ break ;
1424+ }
1425+ } ) ;
14121426
1413- switch ( scmResource . type ) {
1414- case Status . UNTRACKED :
1415- case Status . IGNORED :
1416- toClean . push ( fsPath ) ;
1417- break ;
1427+ await this . repository . clean ( toClean ) ;
1428+ await this . repository . checkout ( '' , toCheckout ) ;
1429+ await this . repository . updateSubmodules ( submodulesToUpdate ) ;
14181430
1419- default :
1420- toCheckout . push ( fsPath ) ;
1421- break ;
1422- }
1423- } ) ;
1431+ this . closeDiffEditors ( [ ] , [ ...toClean , ...toCheckout ] ) ;
1432+ } ,
1433+ ( ) => {
1434+ const resourcePaths = resources . map ( r => r . fsPath ) ;
1435+
1436+ // Remove resource(s) from working group
1437+ const workingTreeGroup = this . workingTreeGroup . resourceStates
1438+ . filter ( r => ! resourcePaths . includes ( r . resourceUri . fsPath ) ) ;
14241439
1425- await this . repository . clean ( toClean ) ;
1426- await this . repository . checkout ( '' , toCheckout ) ;
1427- await this . repository . updateSubmodules ( submodulesToUpdate ) ;
1440+ // Remove resource(s) from untracked group
1441+ const untrackedGroup = this . untrackedGroup . resourceStates
1442+ . filter ( r => ! resourcePaths . includes ( r . resourceUri . fsPath ) ) ;
14281443
1429- this . closeDiffEditors ( [ ] , [ ... toClean , ... toCheckout ] ) ;
1430- } ) ;
1444+ return { workingTreeGroup , untrackedGroup } ;
1445+ } ) ;
14311446 }
14321447
14331448 closeDiffEditors ( indexResources : string [ ] | undefined , workingTreeResources : string [ ] | undefined , ignoreSetting : boolean = false ) : void {
0 commit comments