diff --git a/src/commands/openFileInRemote.ts b/src/commands/openFileInRemote.ts index c7be70d..9893d84 100644 --- a/src/commands/openFileInRemote.ts +++ b/src/commands/openFileInRemote.ts @@ -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; } @@ -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); } @@ -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); @@ -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 diff --git a/src/views/branchHistoryNode.ts b/src/views/branchHistoryNode.ts index 6e54423..5cff697 100644 --- a/src/views/branchHistoryNode.ts +++ b/src/views/branchHistoryNode.ts @@ -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)]; diff --git a/src/views/commitFileNode.ts b/src/views/commitFileNode.ts index 57ed32f..3ffb5b9 100644 --- a/src/views/commitFileNode.ts +++ b/src/views/commitFileNode.ts @@ -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 })); } diff --git a/src/views/commitNode.ts b/src/views/commitNode.ts index 5e60f34..7b93c53 100644 --- a/src/views/commitNode.ts +++ b/src/views/commitNode.ts @@ -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)); } @@ -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 {