Skip to content

Commit 8febb67

Browse files
committed
Fixes broken open revision command
1 parent 6c4995d commit 8febb67

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1717
### Fixed
1818

1919
- Fixes issues with the _Line History_ view sometimes showing a duplicate and out of order commit
20-
- Fixes the broken _Open File_ command on the root node of the _File History_ and _Line History_ views
20+
- Fixes broken _Open File_ command on the root node of the _File History_ and _Line History_ views
21+
- Fixes broken _Open Revision_ command on status files of the _Repositories_ view
2122

2223
## [9.6.0] - 2019-04-08
2324

src/git/gitUri.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class GitUri extends ((Uri as any) as UriEx) {
333333
const path = GitUri.resolve(fileName, repoPath);
334334
return Uri.parse(
335335
// Change encoded / back to / otherwise uri parsing won't work properly
336-
`git:${encodeURIComponent(path).replace(/%2F/g, slash)}?${encodeURIComponent(
336+
`${DocumentSchemes.Git}:${encodeURIComponent(path).replace(/%2F/g, slash)}?${encodeURIComponent(
337337
JSON.stringify({
338338
// Ensure we use the fsPath here, otherwise the url won't open properly
339339
path: Uri.file(path).fsPath,
@@ -396,6 +396,14 @@ export class GitUri extends ((Uri as any) as UriEx) {
396396
shortSha = uriOrRef.shortSha;
397397
}
398398

399+
if (ref === undefined || GitService.isUncommitted(ref)) {
400+
if (GitService.isStagedUncommitted(ref)) {
401+
return GitUri.git(fileName, repoPath);
402+
}
403+
404+
return Uri.file(fileName);
405+
}
406+
399407
const filePath = Strings.normalizePath(fileName, { addLeadingSlash: true });
400408
const data: UriRevisionData = {
401409
path: filePath,

src/views/viewCommands.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ import {
2222
BranchTrackingStatusNode,
2323
CommitFileNode,
2424
CommitNode,
25+
ContributorNode,
26+
FileHistoryNode,
2527
FolderNode,
28+
LineHistoryNode,
2629
RemoteNode,
2730
RepositoryNode,
2831
ResultsFileNode,
@@ -34,10 +37,7 @@ import {
3437
ViewRefNode,
3538
viewSupportsNodeDismissal
3639
} from './nodes';
37-
import { ContributorNode } from './nodes/contributorNode';
3840
import { Strings } from '../system/string';
39-
import { FileHistoryNode } from './nodes/fileHistoryNode';
40-
import { LineHistoryNode } from './nodes/lineHistoryNode';
4141

4242
export interface RefreshNodeCommandArgs {
4343
maxCount?: number;
@@ -392,10 +392,17 @@ export class ViewCommands implements Disposable {
392392
}
393393

394394
private openFileRevision(
395-
node: CommitFileNode | ResultsFileNode | StashFileNode,
395+
node: CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode,
396396
options: OpenFileRevisionCommandArgs = { showOptions: { preserveFocus: true, preview: false } }
397397
) {
398-
if (!(node instanceof CommitFileNode) && !(node instanceof ResultsFileNode)) return undefined;
398+
if (
399+
!(node instanceof CommitFileNode) &&
400+
!(node instanceof StashFileNode) &&
401+
!(node instanceof ResultsFileNode) &&
402+
!(node instanceof StatusFileNode)
403+
) {
404+
return undefined;
405+
}
399406

400407
let uri = options.uri;
401408
if (uri == null) {
@@ -417,6 +424,19 @@ export class ViewCommands implements Disposable {
417424
return openEditor(uri, options.showOptions || { preserveFocus: true, preview: false });
418425
}
419426

427+
private openFileRevisionInRemote(node: CommitFileNode) {
428+
if (!(node instanceof CommitFileNode) || node instanceof StashFileNode) return undefined;
429+
430+
const args: OpenFileInRemoteCommandArgs = {
431+
range: false
432+
};
433+
return commands.executeCommand(
434+
Commands.OpenFileInRemote,
435+
node.commit.toGitUri(node.commit.status === 'D'),
436+
args
437+
);
438+
}
439+
420440
private async openChangedFileChanges(
421441
node: CommitNode | StashNode,
422442
options: TextDocumentShowOptions = { preserveFocus: false, preview: false }
@@ -503,19 +523,6 @@ export class ViewCommands implements Disposable {
503523
return commands.executeCommand(Commands.DiffWith, diffArgs);
504524
}
505525

506-
private openFileRevisionInRemote(node: CommitFileNode | StashFileNode | StatusFileNode) {
507-
if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return undefined;
508-
509-
const args: OpenFileInRemoteCommandArgs = {
510-
range: false
511-
};
512-
return commands.executeCommand(
513-
Commands.OpenFileInRemote,
514-
node.commit.toGitUri(node.commit.status === 'D'),
515-
args
516-
);
517-
}
518-
519526
private openInTerminal(node: RepositoryNode) {
520527
if (!(node instanceof RepositoryNode)) return undefined;
521528

0 commit comments

Comments
 (0)