Git - add setting for untracked changes soft delete (#240387)

This commit is contained in:
Ladislau Szomoru
2025-02-11 17:20:26 +01:00
committed by GitHub
parent 9c1fb6ebdc
commit 6272008be1
3 changed files with 19 additions and 2 deletions

View File

@@ -3324,6 +3324,12 @@
"default": [],
"markdownDescription": "%config.diagnosticsCommitHook.Source%",
"scope": "resource"
},
"git.untrackedChangesSoftDelete": {
"type": "boolean",
"default": true,
"markdownDescription": "%config.untrackedChangesSoftDelete%",
"scope": "resource"
}
}
},

View File

@@ -292,6 +292,7 @@
"config.diagnosticsCommitHook.Severity.information": "Errors, warnings, and information",
"config.diagnosticsCommitHook.Severity.hint": "Errors, warnings, information, and hints",
"config.diagnosticsCommitHook.Source": "Controls the list of diagnostics sources for which Git should check before committing.",
"config.untrackedChangesSoftDelete": "Controls whether discarding untracked changes moves the file(s) to the Recycle Bin (Windows), Trash (macOS, Linux) instead of deleting them.",
"submenu.explorer": "Git",
"submenu.commit": "Commit",
"submenu.commit.amend": "Amend",

View File

@@ -23,7 +23,7 @@ import { IPushErrorHandlerRegistry } from './pushError';
import { IRemoteSourcePublisherRegistry } from './remotePublisher';
import { StatusBarCommands } from './statusbar';
import { toGitUri } from './uri';
import { anyEvent, combinedDisposable, debounceEvent, dispose, EmptyDisposable, eventToPromise, filterEvent, find, getCommitShortHash, IDisposable, isDescendant, onceEvent, pathEquals, relativePath } from './util';
import { anyEvent, combinedDisposable, debounceEvent, dispose, EmptyDisposable, eventToPromise, filterEvent, find, getCommitShortHash, IDisposable, isDescendant, Limiter, onceEvent, pathEquals, relativePath } from './util';
import { IFileWatcher, watch } from './watch';
import { detectEncoding } from './encoding';
import { ISourceControlHistoryItemDetailsProviderRegistry } from './historyItemDetailsProvider';
@@ -1373,6 +1373,9 @@ export class Repository implements Disposable {
}
async clean(resources: Uri[]): Promise<void> {
const config = workspace.getConfiguration('git', Uri.file(this.root));
const untrackedChangesSoftDelete = config.get<boolean>('untrackedChangesSoftDelete', true) === true;
await this.run(
Operation.Clean(!this.optimisticUpdateEnabled()),
async () => {
@@ -1410,7 +1413,14 @@ export class Repository implements Disposable {
}
});
await this.repository.clean(toClean);
if (untrackedChangesSoftDelete) {
const limiter = new Limiter<void>(5);
await Promise.all(toClean.map(fsPath => limiter.queue(
async () => await workspace.fs.delete(Uri.file(fsPath), { useTrash: true }))));
} else {
await this.repository.clean(toClean);
}
try {
await this.repository.checkout('', toCheckout);
} catch (err) {