diff --git a/extensions/git/package.json b/extensions/git/package.json index 3173dfddf528cd186ce824bebc295aa435ff70ca..88034d6c62c5d9b2ea4f0e34a73754eaf7eaf795 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -771,16 +771,6 @@ "type": "boolean", "description": "%config.enableCommitSigning%", "default": false - }, - "git.discardAllScope": { - "type": "string", - "enum": [ - "all", - "tracked", - "prompt" - ], - "description": "%config.discardAllScope%", - "default": false } } } diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 86261a370fa7cf34a17b35cf7dbe3bd29675f75a..f50be185e5ac85b6068455dfc72661a681ff49a6 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -639,54 +639,73 @@ export class CommandCenter { @command('git.cleanAll') async cleanAll(): Promise { - const config = workspace.getConfiguration('git'); - let scope = config.get('discardAllScope') || 'prompt'; let resources = this.model.workingTreeGroup.resources; if (resources.length === 0) { return; } - const untrackedCount = resources.reduce((s, r) => s + (r.type === Status.UNTRACKED ? 1 : 0), 0); + const trackedResources = resources.filter(r => r.type !== Status.UNTRACKED && r.type !== Status.IGNORED); + const untrackedResources = resources.filter(r => r.type === Status.UNTRACKED || r.type === Status.IGNORED); - if (scope === 'prompt' && untrackedCount > 0) { - const message = localize('there are untracked files', "There are untracked files ({0}) which will be DELETED if discarded.\n\nWould you like to delete untracked files when discarding all changes?", untrackedCount); - const yes = localize('yes', "Yes"); - const always = localize('always', "Always"); - const no = localize('no', "No"); - const never = localize('never', "Never"); - const pick = await window.showWarningMessage(message, { modal: true }, yes, always, no, never); + if (untrackedResources.length === 0) { + const message = resources.length === 1 + ? localize('confirm discard all single', "Are you sure you want to discard changes in {0}?", path.basename(resources[0].resourceUri.fsPath)) + : localize('confirm discard all', "Are you sure you want to discard ALL changes in {0} files?\nThis is IRREVERSIBLE!\nYour current working set will be FOREVER LOST.", resources.length); + const yes = resources.length === 1 + ? localize('discardAll multiple', "Discard 1 File") + : localize('discardAll', "Discard ALL {0} Files", resources.length); + const pick = await window.showWarningMessage(message, { modal: true }, yes); - if (typeof pick === 'undefined') { + if (pick !== yes) { return; - } else if (pick === always) { - await config.update('discardAllScope', 'all', true); - } else if (pick === never) { - await config.update('discardAllScope', 'tracked', true); } - if (pick === never || pick === no) { - scope = 'tracked'; + await this.model.clean(...resources); + return; + } else if (resources.length === 1) { + const message = localize('confirm delete', "Are you sure you want to DELETE {0}?", path.basename(resources[0].resourceUri.fsPath)); + const yes = localize('delete file', "Delete file"); + const pick = await window.showWarningMessage(message, { modal: true }, yes); + + if (pick !== yes) { + return; } - } - if (scope === 'tracked') { - resources = resources.filter(r => r.type !== Status.UNTRACKED && r.type !== Status.IGNORED); - } + await this.model.clean(...resources); + } else if (trackedResources.length === 0) { + const message = localize('confirm delete multiple', "Are you sure you want to DELETE {0} files?", resources.length); + const yes = localize('delete files', "Delete Files"); + const pick = await window.showWarningMessage(message, { modal: true }, yes); - if (resources.length === 0) { - return; - } + if (pick !== yes) { + return; + } - const message = localize('confirm discard all', "Are you sure you want to discard ALL ({0}) changes?\nThis is IRREVERSIBLE!\nYour current working set will be FOREVER LOST.", resources.length); - const yes = localize('discardAll', "Discard ALL Changes"); - const pick = await window.showWarningMessage(message, { modal: true }, yes); + await this.model.clean(...resources); - if (pick !== yes) { - return; - } + } else { // resources.length > 1 && untrackedResources.length > 0 && trackedResources.length > 0 + const untrackedMessage = untrackedResources.length === 1 + ? localize('there are untracked files single', "The following untracked file will be DELETED FROM DISK if discarded: {0}.", path.basename(untrackedResources[0].resourceUri.fsPath)) + : localize('there are untracked files', "There are {0} untracked files which will be DELETED FROM DISK if discarded.", untrackedResources.length); - await this.model.clean(...resources); + const message = localize('confirm discard all 2', "{0}\n\nThis is IRREVERSIBLE, your current working set will be FOREVER LOST.", untrackedMessage, resources.length); + + const yesTracked = trackedResources.length === 1 + ? localize('yes discard tracked', "Discard 1 Tracked File", trackedResources.length) + : localize('yes discard tracked multiple', "Discard {0} Tracked Files", trackedResources.length); + + const yesAll = localize('discardAll', "Discard ALL {0} Files", resources.length); + const pick = await window.showWarningMessage(message, { modal: true }, yesTracked, yesAll); + + if (pick === yesTracked) { + resources = trackedResources; + } else if (pick !== yesAll) { + return; + } + + await this.model.clean(...resources); + } } private async smartCommit(