Skip to content

Commit

Permalink
add "open old file" git command
Browse files Browse the repository at this point in the history
this implements microsoft#23011
  • Loading branch information
Duroktar committed May 15, 2017
1 parent 78676ce commit 54da935
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
19 changes: 19 additions & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"dark": "resources/icons/dark/open-file.svg"
}
},
{
"command": "git.openOldFile",
"title": "%command.openOldFile%",
"category": "Git"
},
{
"command": "git.stage",
"title": "%command.stage%",
Expand Down Expand Up @@ -226,6 +231,10 @@
"command": "git.openFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.openOldFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.openChange",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
Expand Down Expand Up @@ -477,6 +486,11 @@
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index",
"group": "navigation"
},
{
"command": "git.openOldFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index",
"group": "navigation"
},
{
"command": "git.unstage",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == index",
Expand All @@ -492,6 +506,11 @@
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"group": "navigation"
},
{
"command": "git.openOldFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
"group": "navigation"
},
{
"command": "git.openFile",
"when": "config.git.enabled && scmProvider == git && gitState == idle && scmResourceGroup == workingTree",
Expand Down
1 change: 1 addition & 0 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"command.refresh": "Refresh",
"command.openChange": "Open Changes",
"command.openFile": "Open File",
"command.openOldFile": "Open Old File",
"command.stage": "Stage Changes",
"command.stageAll": "Stage All Changes",
"command.stageSelectedRanges": "Stage Selected Ranges",
Expand Down
30 changes: 29 additions & 1 deletion extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,35 @@ export class CommandCenter {
return await commands.executeCommand<void>('vscode.open', uri);
}

@command('git.openOldFile')
async openOldFile(arg?: Resource | Uri): Promise<void> {
let resource: Resource | undefined = undefined;

if (arg instanceof Resource) {
resource = arg;

} else if (arg instanceof Uri) {
resource = this.getSCMResource(arg);
} else {
resource = this.getSCMResource();
}

if (!resource) {
return;
}
return await this._openOldResource(resource);
}

private async _openOldResource(resource: Resource): Promise<void> {
const old = this.getLeftResource(resource);
const current = this.getRightResource(resource);

if (!old) {
return await commands.executeCommand<void>('vscode.open', current);
}
return await commands.executeCommand<void>('vscode.open', old);
}

@command('git.openChange')
async openChange(arg?: Resource | Uri): Promise<void> {
let resource: Resource | undefined = undefined;
Expand All @@ -290,7 +319,6 @@ export class CommandCenter {
if (!resource) {
return;
}

return await this._openResource(resource);
}

Expand Down

0 comments on commit 54da935

Please sign in to comment.