Skip to content

Commit

Permalink
Fixes broken open revision command
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Apr 17, 2019
1 parent 6c4995d commit 8febb67
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed

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

## [9.6.0] - 2019-04-08

Expand Down
10 changes: 9 additions & 1 deletion src/git/gitUri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class GitUri extends ((Uri as any) as UriEx) {
const path = GitUri.resolve(fileName, repoPath);
return Uri.parse(
// Change encoded / back to / otherwise uri parsing won't work properly
`git:${encodeURIComponent(path).replace(/%2F/g, slash)}?${encodeURIComponent(
`${DocumentSchemes.Git}:${encodeURIComponent(path).replace(/%2F/g, slash)}?${encodeURIComponent(
JSON.stringify({
// Ensure we use the fsPath here, otherwise the url won't open properly
path: Uri.file(path).fsPath,
Expand Down Expand Up @@ -396,6 +396,14 @@ export class GitUri extends ((Uri as any) as UriEx) {
shortSha = uriOrRef.shortSha;
}

if (ref === undefined || GitService.isUncommitted(ref)) {
if (GitService.isStagedUncommitted(ref)) {
return GitUri.git(fileName, repoPath);
}

return Uri.file(fileName);
}

const filePath = Strings.normalizePath(fileName, { addLeadingSlash: true });
const data: UriRevisionData = {
path: filePath,
Expand Down
43 changes: 25 additions & 18 deletions src/views/viewCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import {
BranchTrackingStatusNode,
CommitFileNode,
CommitNode,
ContributorNode,
FileHistoryNode,
FolderNode,
LineHistoryNode,
RemoteNode,
RepositoryNode,
ResultsFileNode,
Expand All @@ -34,10 +37,7 @@ import {
ViewRefNode,
viewSupportsNodeDismissal
} from './nodes';
import { ContributorNode } from './nodes/contributorNode';
import { Strings } from '../system/string';
import { FileHistoryNode } from './nodes/fileHistoryNode';
import { LineHistoryNode } from './nodes/lineHistoryNode';

export interface RefreshNodeCommandArgs {
maxCount?: number;
Expand Down Expand Up @@ -392,10 +392,17 @@ export class ViewCommands implements Disposable {
}

private openFileRevision(
node: CommitFileNode | ResultsFileNode | StashFileNode,
node: CommitFileNode | ResultsFileNode | StashFileNode | StatusFileNode,
options: OpenFileRevisionCommandArgs = { showOptions: { preserveFocus: true, preview: false } }
) {
if (!(node instanceof CommitFileNode) && !(node instanceof ResultsFileNode)) return undefined;
if (
!(node instanceof CommitFileNode) &&
!(node instanceof StashFileNode) &&
!(node instanceof ResultsFileNode) &&
!(node instanceof StatusFileNode)
) {
return undefined;
}

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

private openFileRevisionInRemote(node: CommitFileNode) {
if (!(node instanceof CommitFileNode) || node instanceof StashFileNode) return undefined;

const args: OpenFileInRemoteCommandArgs = {
range: false
};
return commands.executeCommand(
Commands.OpenFileInRemote,
node.commit.toGitUri(node.commit.status === 'D'),
args
);
}

private async openChangedFileChanges(
node: CommitNode | StashNode,
options: TextDocumentShowOptions = { preserveFocus: false, preview: false }
Expand Down Expand Up @@ -503,19 +523,6 @@ export class ViewCommands implements Disposable {
return commands.executeCommand(Commands.DiffWith, diffArgs);
}

private openFileRevisionInRemote(node: CommitFileNode | StashFileNode | StatusFileNode) {
if (!(node instanceof CommitFileNode) && !(node instanceof StatusFileNode)) return undefined;

const args: OpenFileInRemoteCommandArgs = {
range: false
};
return commands.executeCommand(
Commands.OpenFileInRemote,
node.commit.toGitUri(node.commit.status === 'D'),
args
);
}

private openInTerminal(node: RepositoryNode) {
if (!(node instanceof RepositoryNode)) return undefined;

Expand Down

0 comments on commit 8febb67

Please sign in to comment.