diff --git a/extensions/git/package.nls.json b/extensions/git/package.nls.json index 97ae29eae20..a9850cbb978 100644 --- a/extensions/git/package.nls.json +++ b/extensions/git/package.nls.json @@ -4,15 +4,15 @@ "command.refresh": "Refresh", "command.openChange": "Open Change", "command.openFile": "Open File", - "command.stage": "Stage", - "command.stageAll": "Stage All", + "command.stage": "Stage File", + "command.stageAll": "Stage All Files", "command.stageSelectedRanges": "Stage Selected Ranges", "command.revertSelectedRanges": "Revert Selected Ranges", - "command.unstage": "Unstage", - "command.unstageAll": "Unstage All", + "command.unstage": "Unstage File", + "command.unstageAll": "Unstage All Files", "command.unstageSelectedRanges": "Unstage Selected Ranges", - "command.clean": "Clean", - "command.cleanAll": "Clean All", + "command.clean": "Clean File", + "command.cleanAll": "Clean All Files", "command.commit": "Commit", "command.commitStaged": "Commit Staged", "command.commitStagedSigned": "Commit Staged (Signed Off)", diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 9bc2e3775b7..5ad8ce2d382 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -5,7 +5,7 @@ 'use strict'; -import { Uri, commands, scm, Disposable, SCMResourceGroup, SCMResource, window, workspace, QuickPickItem, OutputChannel, computeDiff, Range, WorkspaceEdit, Position } from 'vscode'; +import { Uri, commands, scm, Disposable, window, workspace, QuickPickItem, OutputChannel, computeDiff, Range, WorkspaceEdit, Position } from 'vscode'; import { Ref, RefType } from './git'; import { Model, Resource, Status, CommitOptions } from './model'; import * as staging from './staging'; @@ -16,24 +16,6 @@ import * as nls from 'vscode-nls'; const localize = nls.loadMessageBundle(); -function resolveGitURI(uri: Uri): SCMResource | SCMResourceGroup | undefined { - if (uri.authority !== 'git') { - return; - } - - return scm.getResourceFromURI(uri); -} - -function resolveGitResource(uri: Uri): Resource | undefined { - const resource = resolveGitURI(uri); - - if (!(resource instanceof Resource)) { - return; - } - - return resource; -} - class CheckoutItem implements QuickPickItem { protected get shortCommit(): string { return (this.ref.commit || '').substr(0, 8); } @@ -226,38 +208,30 @@ export class CommandCenter { } @command('git.openFile') - async openFile(uri: Uri): Promise { - const scmResource = resolveGitResource(uri); + async openFile(uri?: Uri): Promise { + const resource = this.resolveSCMResource(uri); - if (scmResource) { - return await commands.executeCommand('vscode.open', scmResource.uri); + if (!resource) { + return; } - return await commands.executeCommand('vscode.open', uri.with({ scheme: 'file' })); + return await commands.executeCommand('vscode.open', resource.uri); } @command('git.openChange') - async openChange(uri: Uri): Promise { - const scmResource = resolveGitResource(uri); + async openChange(uri?: Uri): Promise { + const resource = this.resolveSCMResource(uri); - if (scmResource) { - return await this.open(scmResource); + if (!resource) { + return; } - if (uri.scheme === 'file') { - const uriString = uri.toString(); - const resource = this.model.workingTreeGroup.resources.filter(r => r.uri.toString() === uriString)[0] - || this.model.indexGroup.resources.filter(r => r.uri.toString() === uriString)[0]; - - if (resource) { - return await this.open(resource); - } - } + return await this.open(resource); } @command('git.stage') - async stage(uri: Uri): Promise { - const resource = resolveGitResource(uri); + async stage(uri?: Uri): Promise { + const resource = this.resolveSCMResource(uri); if (!resource) { return; @@ -353,8 +327,8 @@ export class CommandCenter { } @command('git.unstage') - async unstage(uri: Uri): Promise { - const resource = resolveGitResource(uri); + async unstage(uri?: Uri): Promise { + const resource = this.resolveSCMResource(uri); if (!resource) { return; @@ -411,8 +385,8 @@ export class CommandCenter { } @command('git.clean') - async clean(uri: Uri): Promise { - const resource = resolveGitResource(uri); + async clean(uri?: Uri): Promise { + const resource = this.resolveSCMResource(uri); if (!resource) { return; @@ -743,6 +717,30 @@ export class CommandCenter { }; } + private resolveSCMResource(uri?: Uri): Resource | undefined { + uri = uri || window.activeTextEditor && window.activeTextEditor.document.uri; + + if (!uri) { + return; + } + + if (uri.scheme === 'scm' && uri.authority === 'git') { + const resource = scm.getResourceFromURI(uri); + return resource instanceof Resource ? resource : undefined; + } + + if (uri.scheme === 'git') { + uri = uri.with({ scheme: 'file' }); + } + + if (uri.scheme === 'file') { + const uriString = uri.toString(); + + return this.model.workingTreeGroup.resources.filter(r => r.uri.toString() === uriString)[0] + || this.model.indexGroup.resources.filter(r => r.uri.toString() === uriString)[0]; + } + } + dispose(): void { this.disposables.forEach(d => d.dispose()); }