Skip to content

Commit 963bf2e

Browse files
authored
Git - handle the scenarion in which Recycle Bin/Trash are not supported (microsoft#249890)
1 parent 7efc870 commit 963bf2e

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

extensions/git/src/repository.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { IPushErrorHandlerRegistry } from './pushError';
2222
import { IRemoteSourcePublisherRegistry } from './remotePublisher';
2323
import { StatusBarCommands } from './statusbar';
2424
import { toGitUri } from './uri';
25-
import { anyEvent, combinedDisposable, debounceEvent, dispose, EmptyDisposable, eventToPromise, filterEvent, find, getCommitShortHash, IDisposable, isDescendant, isLinuxSnap, isRemote, Limiter, onceEvent, pathEquals, relativePath } from './util';
25+
import { anyEvent, combinedDisposable, debounceEvent, dispose, EmptyDisposable, eventToPromise, filterEvent, find, getCommitShortHash, IDisposable, isDescendant, isLinuxSnap, isRemote, isWindows, Limiter, onceEvent, pathEquals, relativePath } from './util';
2626
import { IFileWatcher, watch } from './watch';
2727
import { ISourceControlHistoryItemDetailsProviderRegistry } from './historyItemDetailsProvider';
2828

@@ -1397,9 +1397,29 @@ export class Repository implements Disposable {
13971397

13981398
if (toClean.length > 0) {
13991399
if (discardUntrackedChangesToTrash) {
1400-
const limiter = new Limiter<void>(5);
1401-
await Promise.all(toClean.map(fsPath => limiter.queue(
1402-
async () => await workspace.fs.delete(Uri.file(fsPath), { useTrash: true }))));
1400+
try {
1401+
// Attempt to move the first resource to the recycle bin/trash to check
1402+
// if it is supported. If it fails, we show a confirmation dialog and
1403+
// fall back to deletion.
1404+
await workspace.fs.delete(Uri.file(toClean[0]), { useTrash: true });
1405+
1406+
const limiter = new Limiter<void>(5);
1407+
await Promise.all(toClean.slice(1).map(fsPath => limiter.queue(
1408+
async () => await workspace.fs.delete(Uri.file(fsPath), { useTrash: true }))));
1409+
} catch {
1410+
const message = isWindows
1411+
? l10n.t('Failed to delete using the Recycle Bin. Do you want to permanently delete instead?')
1412+
: l10n.t('Failed to delete using the Trash. Do you want to permanently delete instead?');
1413+
const primaryAction = toClean.length === 1
1414+
? l10n.t('Delete File')
1415+
: l10n.t('Delete All {0} Files', resources.length);
1416+
1417+
const result = await window.showWarningMessage(message, { modal: true }, primaryAction);
1418+
if (result === primaryAction) {
1419+
// Delete permanently
1420+
await this.repository.clean(toClean);
1421+
}
1422+
}
14031423
} else {
14041424
await this.repository.clean(toClean);
14051425
}

0 commit comments

Comments
 (0)