Skip to content

Commit bbe70bc

Browse files
committed
1 parent 0c504ea commit bbe70bc

3 files changed

Lines changed: 71 additions & 7 deletions

File tree

extensions/git/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,16 @@
771771
"type": "boolean",
772772
"description": "%config.enableCommitSigning%",
773773
"default": false
774+
},
775+
"git.discardAllScope": {
776+
"type": "string",
777+
"enum": [
778+
"all",
779+
"tracked",
780+
"prompt"
781+
],
782+
"description": "%config.discardAllScope%",
783+
"default": false
774784
}
775785
}
776786
}

extensions/git/package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@
5252
"config.ignoreLimitWarning": "Ignores the warning when there are too many changes in a repository",
5353
"config.defaultCloneDirectory": "The default location where to clone a git repository",
5454
"config.enableSmartCommit": "Commit all changes when there are no staged changes.",
55-
"config.enableCommitSigning": "Enables commit signing with GPG."
55+
"config.enableCommitSigning": "Enables commit signing with GPG.",
56+
"config.discardAllScope": "Controls what changes are discarded by the `Discard all changes` command. `all` discards all changes. `tracked` discards only tracked files. `prompt` shows a prompt dialog every time the action is run."
5657
}

extensions/git/src/commands.ts

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,25 @@ export class CommandCenter {
603603
return;
604604
}
605605

606-
const message = resources.length === 1
607-
? localize('confirm discard', "Are you sure you want to discard changes in {0}?", path.basename(resources[0].resourceUri.fsPath))
608-
: localize('confirm discard multiple', "Are you sure you want to discard changes in {0} files?", resources.length);
606+
const untrackedCount = resources.reduce((s, r) => s + (r.type === Status.UNTRACKED ? 1 : 0), 0);
607+
let message: string;
608+
let yes = localize('discard', "Discard Changes");
609+
610+
if (resources.length === 1) {
611+
if (untrackedCount > 0) {
612+
message = localize('confirm delete', "Are you sure you want to DELETE {0}?", path.basename(resources[0].resourceUri.fsPath));
613+
yes = localize('delete file', "Delete file");
614+
} else {
615+
message = localize('confirm discard', "Are you sure you want to discard changes in {0}?", path.basename(resources[0].resourceUri.fsPath));
616+
}
617+
} else {
618+
message = localize('confirm discard multiple', "Are you sure you want to discard changes in {0} files?", resources.length);
619+
620+
if (untrackedCount > 0) {
621+
message = `${message}\n\n${localize('warn untracked', "This will DELETE {0} untracked files!", untrackedCount)}`;
622+
}
623+
}
609624

610-
const yes = localize('discard', "Discard Changes");
611625
const pick = await window.showWarningMessage(message, { modal: true }, yes);
612626

613627
if (pick !== yes) {
@@ -619,15 +633,54 @@ export class CommandCenter {
619633

620634
@command('git.cleanAll')
621635
async cleanAll(): Promise<void> {
622-
const message = localize('confirm discard all', "Are you sure you want to discard ALL changes? This is IRREVERSIBLE!");
636+
const config = workspace.getConfiguration('git');
637+
let scope = config.get<string>('discardAllScope') || 'prompt';
638+
let resources = this.model.workingTreeGroup.resources;
639+
640+
if (resources.length === 0) {
641+
return;
642+
}
643+
644+
const untrackedCount = resources.reduce((s, r) => s + (r.type === Status.UNTRACKED ? 1 : 0), 0);
645+
646+
if (scope === 'prompt' && untrackedCount > 0) {
647+
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);
648+
const yes = localize('yes', "Yes");
649+
const always = localize('always', "Always");
650+
const no = localize('no', "No");
651+
const never = localize('never', "Never");
652+
const pick = await window.showWarningMessage(message, { modal: true }, yes, always, no, never);
653+
654+
if (typeof pick === 'undefined') {
655+
return;
656+
} else if (pick === always) {
657+
await config.update('discardAllScope', 'all', true);
658+
} else if (pick === never) {
659+
await config.update('discardAllScope', 'tracked', true);
660+
}
661+
662+
if (pick === never || pick === no) {
663+
scope = 'tracked';
664+
}
665+
}
666+
667+
if (scope === 'tracked') {
668+
resources = resources.filter(r => r.type !== Status.UNTRACKED && r.type !== Status.IGNORED);
669+
}
670+
671+
if (resources.length === 0) {
672+
return;
673+
}
674+
675+
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);
623676
const yes = localize('discardAll', "Discard ALL Changes");
624677
const pick = await window.showWarningMessage(message, { modal: true }, yes);
625678

626679
if (pick !== yes) {
627680
return;
628681
}
629682

630-
await this.model.clean(...this.model.workingTreeGroup.resources);
683+
await this.model.clean(...resources);
631684
}
632685

633686
private async smartCommit(

0 commit comments

Comments
 (0)