diff --git a/extensions/git/package.json b/extensions/git/package.json index 6f9405280d1..07e56d131c8 100644 --- a/extensions/git/package.json +++ b/extensions/git/package.json @@ -109,6 +109,15 @@ "dark": "resources/icons/dark/stage.svg" } }, + { + "command": "git.stageAllTracked", + "title": "%command.stageAllTracked%", + "category": "Git", + "icon": { + "light": "resources/icons/light/stage.svg", + "dark": "resources/icons/dark/stage.svg" + } + }, { "command": "git.stageAllUntracked", "title": "%command.stageAllUntracked%", @@ -187,6 +196,15 @@ "dark": "resources/icons/dark/clean.svg" } }, + { + "command": "git.cleanAllTracked", + "title": "%command.cleanAllTracked%", + "category": "Git", + "icon": { + "light": "resources/icons/light/clean.svg", + "dark": "resources/icons/dark/clean.svg" + } + }, { "command": "git.cleanAllUntracked", "title": "%command.cleanAllUntracked%", @@ -468,6 +486,10 @@ "command": "git.stageAll", "when": "config.git.enabled && gitOpenRepositoryCount != 0" }, + { + "command": "git.stageAllTracked", + "when": "config.git.enabled && gitOpenRepositoryCount != 0" + }, { "command": "git.stageAllUntracked", "when": "config.git.enabled && gitOpenRepositoryCount != 0" @@ -885,22 +907,42 @@ }, { "command": "git.cleanAll", - "when": "scmProvider == git && scmResourceGroup == workingTree", + "when": "scmProvider == git && scmResourceGroup == workingTree && config.git.handleUntracked == withchanges", "group": "1_modification" }, { "command": "git.stageAll", - "when": "scmProvider == git && scmResourceGroup == workingTree", + "when": "scmProvider == git && scmResourceGroup == workingTree && config.git.handleUntracked == withchanges", "group": "1_modification" }, { "command": "git.cleanAll", - "when": "scmProvider == git && scmResourceGroup == workingTree", + "when": "scmProvider == git && scmResourceGroup == workingTree && config.git.handleUntracked == withchanges", "group": "inline" }, { "command": "git.stageAll", - "when": "scmProvider == git && scmResourceGroup == workingTree", + "when": "scmProvider == git && scmResourceGroup == workingTree && config.git.handleUntracked == withchanges", + "group": "inline" + }, + { + "command": "git.cleanAllTracked", + "when": "scmProvider == git && scmResourceGroup == workingTree && config.git.handleUntracked != withchanges", + "group": "1_modification" + }, + { + "command": "git.stageAllTracked", + "when": "scmProvider == git && scmResourceGroup == workingTree && config.git.handleUntracked != withchanges", + "group": "1_modification" + }, + { + "command": "git.cleanAllTracked", + "when": "scmProvider == git && scmResourceGroup == workingTree && config.git.handleUntracked != withchanges", + "group": "inline" + }, + { + "command": "git.stageAllTracked", + "when": "scmProvider == git && scmResourceGroup == workingTree && config.git.handleUntracked != withchanges", "group": "inline" }, { diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 9800a96b6c9..818293826b6 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -11,6 +11,7 @@ "command.openHEADFile": "Open File (HEAD)", "command.stage": "Stage Changes", "command.stageAll": "Stage All Changes", + "command.stageAllTracked": "Stage All Tracked Changes", "command.stageAllUntracked": "Stage All Untracked Changes", "command.stageSelectedRanges": "Stage Selected Ranges", "command.revertSelectedRanges": "Revert Selected Ranges", @@ -21,6 +22,7 @@ "command.unstageSelectedRanges": "Unstage Selected Ranges", "command.clean": "Discard Changes", "command.cleanAll": "Discard All Changes", + "command.cleanAllTracked": "Discard All Tracked Changes", "command.cleanAllUntracked": "Discard All Untracked Changes", "command.commit": "Commit", "command.commitStaged": "Commit Staged", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 42d36317160..0097b64d8e3 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -954,6 +954,15 @@ export class CommandCenter { } } + @command('git.stageAllTracked', { repository: true }) + async stageAllTracked(repository: Repository): Promise { + const resources = repository.workingTreeGroup.resourceStates + .filter(r => r.type !== Status.UNTRACKED && r.type !== Status.IGNORED); + const uris = resources.map(r => r.resourceUri); + + await repository.add(uris); + } + @command('git.stageAllUntracked', { repository: true }) async stageAllUntracked(repository: Repository): Promise { const resources = [...repository.workingTreeGroup.resourceStates, ...repository.untrackedGroup.resourceStates] @@ -1207,26 +1216,11 @@ export class CommandCenter { const untrackedResources = resources.filter(r => r.type === Status.UNTRACKED || r.type === Status.IGNORED); 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 (pick !== yes) { - return; - } - - await repository.clean(resources.map(r => r.resourceUri)); - + await this._cleanTrackedChanges(repository, resources); } else if (resources.length === 1) { await this._cleanUntrackedChange(repository, resources[0]); - } else if (trackedResources.length === 0) { await this._cleanUntrackedChanges(repository, resources); - } 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)) @@ -1251,6 +1245,18 @@ export class CommandCenter { } } + @command('git.cleanAllTracked', { repository: true }) + async cleanAllTracked(repository: Repository): Promise { + const resources = repository.workingTreeGroup.resourceStates + .filter(r => r.type !== Status.UNTRACKED && r.type !== Status.IGNORED); + + if (resources.length === 0) { + return; + } + + await this._cleanTrackedChanges(repository, resources); + } + @command('git.cleanAllUntracked', { repository: true }) async cleanAllUntracked(repository: Repository): Promise { const resources = [...repository.workingTreeGroup.resourceStates, ...repository.untrackedGroup.resourceStates] @@ -1267,6 +1273,22 @@ export class CommandCenter { } } + private async _cleanTrackedChanges(repository: Repository, resources: Resource[]): Promise { + 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 (pick !== yes) { + return; + } + + await repository.clean(resources.map(r => r.resourceUri)); + } + private async _cleanUntrackedChange(repository: Repository, resource: Resource): Promise { const message = localize('confirm delete', "Are you sure you want to DELETE {0}?\nThis is IRREVERSIBLE!\nThis file will be FOREVER LOST.", path.basename(resource.resourceUri.fsPath)); const yes = localize('delete file', "Delete file");