Skip to content

Commit

Permalink
Fixes issue where the revision wasn't properly opened
Browse files Browse the repository at this point in the history
Adds ability to provide a branch to open file in remote
  • Loading branch information
eamodio committed Sep 12, 2017
1 parent 9464f7e commit 503b2a3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
17 changes: 13 additions & 4 deletions src/commands/openFileInRemote.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';
import { Arrays } from '../system';
import { commands, Range, TextEditor, Uri, window } from 'vscode';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, isCommandViewContextWithCommit } from './common';
import { ActiveEditorCommand, CommandContext, Commands, getCommandUri, isCommandViewContextWithBranch, isCommandViewContextWithCommit } from './common';
import { GitService, GitUri } from '../gitService';
import { Logger } from '../logger';
import { OpenInRemoteCommandArgs } from './openInRemote';

export interface OpenFileInRemoteCommandArgs {
branch?: string;
range?: boolean;
}

Expand All @@ -20,6 +21,9 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
if (isCommandViewContextWithCommit(context)) {
args = { ...args };
args.range = false;
if (isCommandViewContextWithBranch(context)) {
args.branch = context.node.branch !== undefined ? context.node.branch.name : undefined;
}
return this.execute(context.editor, context.node.commit.uri, args);
}

Expand All @@ -33,7 +37,12 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
const gitUri = await GitUri.fromUri(uri, this.git);
if (!gitUri.repoPath) return undefined;

const branch = await this.git.getBranch(gitUri.repoPath);
if (args.branch === undefined) {
const branch = await this.git.getBranch(gitUri.repoPath);
if (branch !== undefined) {
args.branch = branch.name;
}
}

try {
const remotes = Arrays.uniqueBy(await this.git.getRemotes(gitUri.repoPath), _ => _.url, _ => !!_.provider);
Expand All @@ -43,8 +52,8 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {

return commands.executeCommand(Commands.OpenInRemote, uri, {
resource: {
type: 'file',
branch: branch === undefined ? 'Current' : branch.name,
type: gitUri.sha === undefined ? 'file' : 'revision',
branch: args.branch === undefined ? 'Current' : args.branch,
fileName: gitUri.getRelativePath(),
range: range,
sha: gitUri.sha
Expand Down
2 changes: 1 addition & 1 deletion src/views/branchHistoryNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class BranchHistoryNode extends ExplorerNode {
const log = await this.git.getLogForRepo(this.uri.repoPath!, this.branch.name, this.maxCount);
if (log === undefined) return [];

const children = Iterables.map(log.commits.values(), c => new CommitNode(c, this.template, this.context, this.git));
const children = Iterables.map(log.commits.values(), c => new CommitNode(c, this.template, this.context, this.git, this.branch));
if (!log.truncated) return [...children];

return [...children, new ShowAllCommitsNode(this, this.context)];
Expand Down
4 changes: 2 additions & 2 deletions src/views/commitFileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
import { ExplorerNode, ResourceType } from './explorerNode';
import { getGitStatusIcon, GitCommit, GitService, GitUri, IGitStatusFile, StatusFileFormatter } from '../gitService';
import { getGitStatusIcon, GitBranch, GitCommit, GitService, GitUri, IGitStatusFile, StatusFileFormatter } from '../gitService';
import * as path from 'path';

export class CommitFileNode extends ExplorerNode {

readonly resourceType: ResourceType = 'gitlens:commit-file';

constructor(public readonly status: IGitStatusFile, public commit: GitCommit, protected readonly context: ExtensionContext, protected readonly git: GitService) {
constructor(public readonly status: IGitStatusFile, public commit: GitCommit, protected readonly context: ExtensionContext, protected readonly git: GitService, public readonly branch?: GitBranch) {
super(new GitUri(Uri.file(path.resolve(commit.repoPath, status.fileName)), { repoPath: commit.repoPath, fileName: status.fileName, sha: commit.sha }));
}

Expand Down
6 changes: 3 additions & 3 deletions src/views/commitNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { Command, ExtensionContext, TreeItem, TreeItemCollapsibleState } from 'v
import { Commands, DiffWithPreviousCommandArgs } from '../commands';
import { CommitFileNode } from './commitFileNode';
import { ExplorerNode, ResourceType } from './explorerNode';
import { CommitFormatter, getGitStatusIcon, GitLogCommit, GitService, GitUri, ICommitFormatOptions } from '../gitService';
import { CommitFormatter, getGitStatusIcon, GitBranch, GitLogCommit, GitService, GitUri, ICommitFormatOptions } from '../gitService';
import * as path from 'path';

export class CommitNode extends ExplorerNode {

readonly resourceType: ResourceType = 'gitlens:commit';

constructor(public readonly commit: GitLogCommit, private readonly template: string, protected readonly context: ExtensionContext, protected readonly git: GitService) {
constructor(public readonly commit: GitLogCommit, private readonly template: string, protected readonly context: ExtensionContext, protected readonly git: GitService, public readonly branch?: GitBranch) {
super(new GitUri(commit.uri, commit));
}

Expand All @@ -24,7 +24,7 @@ export class CommitNode extends ExplorerNode {
const commit = Iterables.first(log.commits.values());
if (commit === undefined) return [];

return [...Iterables.map(commit.fileStatuses, s => new CommitFileNode(s, commit, this.context, this.git))];
return [...Iterables.map(commit.fileStatuses, s => new CommitFileNode(s, commit, this.context, this.git, this.branch))];
}

getTreeItem(): TreeItem {
Expand Down

0 comments on commit 503b2a3

Please sign in to comment.