Browse Source

Closes #646 - adds open revision from branch command

main
Eric Amodio 5 years ago
parent
commit
d2d12e7c27
6 changed files with 75 additions and 3 deletions
  1. +9
    -0
      package.json
  2. +1
    -0
      src/commands.ts
  3. +1
    -0
      src/commands/common.ts
  4. +1
    -1
      src/commands/openFileRevision.ts
  5. +58
    -0
      src/commands/openFileRevisionFromBranch.ts
  6. +5
    -2
      src/quickpicks/branchesAndTagsQuickPick.ts

+ 9
- 0
package.json View File

@ -2114,6 +2114,11 @@
"category": "GitLens"
},
{
"command": "gitlens.openFileRevisionFromBranch",
"title": "Open Revision from Branch or Tag...",
"category": "GitLens"
},
{
"command": "gitlens.openRepoInRemote",
"title": "Open Repository on Remote",
"category": "GitLens",
@ -3037,6 +3042,10 @@
"when": "gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.openFileRevisionFromBranch",
"when": "gitlens:activeFileStatus =~ /tracked/"
},
{
"command": "gitlens.openRepoInRemote",
"when": "gitlens:hasRemotes"
},

+ 1
- 0
src/commands.ts View File

@ -23,6 +23,7 @@ export * from './commands/openChangedFiles';
export * from './commands/openCommitInRemote';
export * from './commands/openFileInRemote';
export * from './commands/openFileRevision';
export * from './commands/openFileRevisionFromBranch';
export * from './commands/openInRemote';
export * from './commands/openRepoInRemote';
export * from './commands/openWorkingFile';

+ 1
- 0
src/commands/common.ts View File

@ -51,6 +51,7 @@ export enum Commands {
OpenCommitInRemote = 'gitlens.openCommitInRemote',
OpenFileInRemote = 'gitlens.openFileInRemote',
OpenFileRevision = 'gitlens.openFileRevision',
OpenFileRevisionFromBranch = 'gitlens.openFileRevisionFromBranch',
OpenInRemote = 'gitlens.openInRemote',
OpenRepoInRemote = 'gitlens.openRepoInRemote',
OpenWorkingFile = 'gitlens.openWorkingFile',

+ 1
- 1
src/commands/openFileRevision.ts View File

@ -51,7 +51,7 @@ export class OpenFileRevisionCommand extends ActiveEditorCommand {
super(Commands.OpenFileRevision);
}
async execute(editor: TextEditor, uri?: Uri, args: OpenFileRevisionCommandArgs = {}) {
async execute(editor: TextEditor | undefined, uri?: Uri, args: OpenFileRevisionCommandArgs = {}) {
args = { ...args };
if (args.line === undefined) {
args.line = editor == null ? 0 : editor.selection.active.line;

+ 58
- 0
src/commands/openFileRevisionFromBranch.ts View File

@ -0,0 +1,58 @@
'use strict';
import { Range, TextDocumentShowOptions, TextEditor, Uri } from 'vscode';
import { GlyphChars } from '../constants';
import { GitBranch, GitTag, GitUri } from '../git/gitService';
import { BranchesAndTagsQuickPick, BranchQuickPickItem, TagQuickPickItem } from '../quickpicks';
import { Strings } from '../system';
import { ActiveEditorCommand, command, Commands, getCommandUri, openEditor } from './common';
export interface OpenFileRevisionFromBranchCommandArgs {
branchOrTag?: GitBranch | GitTag;
line?: number;
showOptions?: TextDocumentShowOptions;
}
@command()
export class OpenFileRevisionFromBranchCommand extends ActiveEditorCommand {
constructor() {
super(Commands.OpenFileRevisionFromBranch);
}
async execute(editor: TextEditor | undefined, uri?: Uri, args: OpenFileRevisionFromBranchCommandArgs = {}) {
uri = getCommandUri(uri, editor);
if (uri == null) return undefined;
const gitUri = await GitUri.fromUri(uri);
if (!gitUri.repoPath) return undefined;
if (args.branchOrTag === undefined) {
const placeHolder = `Open revision of ${gitUri.getFormattedPath()}${
gitUri.sha ? ` ${Strings.pad(GlyphChars.Dot, 1, 1)} ${gitUri.shortSha}` : ''
} from Branch or Tag${GlyphChars.Ellipsis}`;
const pick = await new BranchesAndTagsQuickPick(gitUri.repoPath).show(placeHolder, {
allowCommitId: false
});
if (pick === undefined) return undefined;
if (!(pick instanceof BranchQuickPickItem) && !(pick instanceof TagQuickPickItem)) {
return undefined;
}
args.branchOrTag = pick.item;
}
if (args.line !== undefined && args.line !== 0) {
if (args.showOptions === undefined) {
args.showOptions = {};
}
args.showOptions.selection = new Range(args.line, 0, args.line, 0);
}
return openEditor(GitUri.toRevisionUri(args.branchOrTag.ref, gitUri.fsPath, gitUri.repoPath), {
...args.showOptions,
rethrow: true
});
}
}

+ 5
- 2
src/quickpicks/branchesAndTagsQuickPick.ts View File

@ -115,7 +115,7 @@ export interface BranchesAndTagsQuickPickOptions {
export class BranchesAndTagsQuickPick {
constructor(
public readonly repoPath: string
public readonly repoPath: string | undefined
) {}
async show(
@ -177,7 +177,10 @@ export class BranchesAndTagsQuickPick {
quickpick.busy = true;
quickpick.enabled = false;
if (await Container.git.validateReference(this.repoPath, ref)) {
if (
this.repoPath === undefined ||
(await Container.git.validateReference(this.repoPath, ref))
) {
resolve(new RefQuickPickItem(ref));
}
else {

Loading…
Cancel
Save