Skip to content

Commit

Permalink
Closes #1071 - adds branch or tag picking
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Dec 6, 2020
1 parent 83c81c2 commit a4b74d0
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Adds `gitlens.heatmap.locations` setting to specify where the indicators of the gutter heatmap annotations will be shown
- Adds a `gitlens.fileAnnotations.command` setting to specify whether the file annotations button in the editor title shows a menu or immediately toggles the specified file annotations — closes [#1165](https://github.com/eamodio/vscode-gitlens/issues/1165) thanks to [PR #1171](https://github.com/eamodio/vscode-gitlens/pull/1171) by Raaj Patil ([@arrpee](https://github.com/arrpee))
- Adds this new option to the _Menus & Toolbars_ section of the GitLens Interactive Settings
- Adds an _Open File on Remote From..._ command (`gitlens.openFileOnRemoteFrom`) to open a file or revision on a specific branch or tag on the remote provider — closes [#1071](https://github.com/eamodio/vscode-gitlens/issues/1071)
- Adds a _Copy Remote File Url From..._ command (`gitlens.copyRemoteFileUrlFrom`) to copy the url of a file or revision on a specific branch or tag the remote provider — closes [#1071](https://github.com/eamodio/vscode-gitlens/issues/1071)
- Adds a welcome, i.e. richer empty state, to the _Search & Compare_ view

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ Additionally, these integrations provide commands to copy the url of or open, fi
- _Open File from Remote_ command (`gitlens.openFileFromRemote`) — opens the local file from a url of a file on a remote provider
- _Open File on Remote_ command (`gitlens.openFileOnRemote`) — opens a file or revision on the remote provider
- _Copy Remote File Url_ command (`gitlens.copyRemoteFileUrlToClipboard`) — copies the url of a file or revision on the remote provider
- _Open File on Remote From..._ command (`gitlens.openFileOnRemoteFrom`) — opens a file or revision on a specific branch or tag on the remote provider
- _Copy Remote File Url From..._ command (`gitlens.copyRemoteFileUrlFrom`) — copies the url of a file or revision on a specific branch or tag the remote provider
- _Open Commit on Remote_ command (`gitlens.openCommitOnRemote`) — opens a commit on the remote provider
- _Copy Remote Commit Url_ command (`gitlens.copyRemoteCommitUrl`) — copies the url of a commit on the remote provider
- _Open Branch on Remote_ command (`gitlens.openBranchOnRemote`) — opens the branch on the remote provider
Expand Down Expand Up @@ -902,7 +904,7 @@ See also [View Settings](#view-settings- 'Jump to the View settings')
| `gitlens.liveshare.allowGuestAccess` | Specifies whether to allow guest access to GitLens features when using Visual Studio Live Share |
| `gitlens.outputLevel` | Specifies how much (if any) output will be sent to the GitLens output channel |
| `gitlens.showWhatsNewAfterUpgrades` | Specifies whether to show What's New after upgrading to new feature releases |
| `gitlens.advanced.abbreviatedShaLength` | Specifies the length of abbreviated commit SHAs (shas) |
| `gitlens.advanced.abbreviatedShaLength` | Specifies the length of abbreviated commit SHAs (shas) |
| `gitlens.advanced.blame.customArguments` | Specifies additional arguments to pass to the `git blame` command |
| `gitlens.advanced.blame.delayAfterEdit` | Specifies the time (in milliseconds) to wait before re-blaming an unsaved document after an edit. Use 0 to specify an infinite wait |
| `gitlens.advanced.blame.sizeThresholdAfterEdit` | Specifies the maximum document size (in lines) allowed to be re-blamed after an edit while still unsaved. Use 0 to specify no maximum |
Expand Down
61 changes: 57 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
"onCommand:gitlens.openFileFromRemote",
"onCommand:gitlens.openFileOnRemote",
"onCommand:gitlens.copyRemoteFileUrlToClipboard",
"onCommand:gitlens.openFileOnRemoteFrom",
"onCommand:gitlens.copyRemoteFileUrlFrom",
"onCommand:gitlens.openFileRevision",
"onCommand:gitlens.openFileRevisionFrom",
"onCommand:gitlens.openPullRequestOnRemote",
Expand Down Expand Up @@ -3158,6 +3160,21 @@
"light": "images/light/icon-copy-link.svg"
}
},
{
"command": "gitlens.openFileOnRemoteFrom",
"title": "Open File on Remote From...",
"category": "GitLens",
"icon": "$(globe)"
},
{
"command": "gitlens.copyRemoteFileUrlFrom",
"title": "Copy Remote File Url From...",
"category": "GitLens",
"icon": {
"dark": "images/dark/icon-copy-link.svg",
"light": "images/light/icon-copy-link.svg"
}
},
{
"command": "gitlens.openFileRevision",
"title": "Open File at Revision...",
Expand Down Expand Up @@ -4802,6 +4819,14 @@
"command": "gitlens.copyRemoteFileUrlToClipboard",
"when": "gitlens:activeFileStatus =~ /tracked/ && gitlens:activeFileStatus =~ /remotes/"
},
{
"command": "gitlens.openFileOnRemoteFrom",
"when": "gitlens:activeFileStatus =~ /tracked/ && gitlens:activeFileStatus =~ /remotes/"
},
{
"command": "gitlens.copyRemoteFileUrlFrom",
"when": "gitlens:activeFileStatus =~ /tracked/ && gitlens:activeFileStatus =~ /remotes/"
},
{
"command": "gitlens.openFileRevision",
"when": "gitlens:activeFileStatus =~ /tracked/"
Expand Down Expand Up @@ -5625,10 +5650,16 @@
"group": "2_gitlens@3",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
},
{
"command": "gitlens.openFileOnRemoteFrom",
"when": "editorTextFocus && gitlens:activeFileStatus =~ /remotes/ && config.gitlens.menus.editor.remote",
"group": "2_gitlens@4",
"alt": "gitlens.copyRemoteFileUrlFrom"
},
{
"command": "gitlens.showFileHistoryInView",
"when": "gitlens:activeFileStatus =~ /tracked/ && config.gitlens.menus.editor.history",
"group": "2_gitlens@4"
"group": "2_gitlens@5"
},
{
"submenu": "gitlens/editor/annotations",
Expand Down Expand Up @@ -5791,10 +5822,16 @@
"group": "2_gitlens@2",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
},
{
"command": "gitlens.openFileOnRemoteFrom",
"when": "gitlens:enabled && gitlens:hasRemotes && config.gitlens.menus.editorTab.remote",
"group": "2_gitlens@3",
"alt": "gitlens.copyRemoteFileUrlFrom"
},
{
"command": "gitlens.showFileHistoryInView",
"when": "gitlens:enabled && config.gitlens.menus.editorTab.history",
"group": "2_gitlens@3"
"group": "2_gitlens@4"
}
],
"explorer/context": [
Expand All @@ -5809,10 +5846,16 @@
"group": "4_gitlens@1",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
},
{
"command": "gitlens.openFileOnRemoteFrom",
"when": "!explorerResourceIsRoot && !explorerResourceIsFolder && gitlens:enabled && gitlens:hasRemotes && config.gitlens.menus.explorer.remote",
"group": "4_gitlens@2",
"alt": "gitlens.copyRemoteFileUrlFrom"
},
{
"command": "gitlens.showFileHistoryInView",
"when": "!explorerResourceIsRoot && !explorerResourceIsFolder && gitlens:enabled && config.gitlens.menus.explorer.history",
"group": "4_gitlens@2"
"group": "4_gitlens@3"
},
{
"command": "gitlens.copyRemoteFileUrlToClipboard",
Expand Down Expand Up @@ -5875,9 +5918,15 @@
{
"command": "gitlens.openFileOnRemote",
"when": "gitlens:enabled && gitlens:hasRemotes && scmProvider == git && scmResourceGroup =~ /^(workingTree|index|merge)$/ && config.gitlens.menus.scmItem.remote",
"group": "navigation@98",
"group": "navigation@97",
"alt": "gitlens.copyRemoteFileUrlToClipboard"
},
{
"command": "gitlens.openFileOnRemoteFrom",
"when": "gitlens:enabled && gitlens:hasRemotes && scmProvider == git && scmResourceGroup =~ /^(workingTree|index|merge)$/ && config.gitlens.menus.scmItem.remote",
"group": "navigation@98",
"alt": "gitlens.copyRemoteFileUrlFrom"
},
{
"command": "gitlens.showFileHistoryInView",
"when": "gitlens:enabled && scmProvider == git && scmResourceGroup =~ /^(workingTree|index|merge)$/ && config.gitlens.menus.scmItem.history",
Expand Down Expand Up @@ -7540,6 +7589,10 @@
{
"command": "gitlens.copyRemoteFileUrlToClipboard",
"group": "2_gitlens@4"
},
{
"command": "gitlens.copyRemoteFileUrlFrom",
"group": "2_gitlens@5"
}
],
"gitlens/editor/context/openChanges": [
Expand Down
2 changes: 2 additions & 0 deletions src/commands/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export enum Commands {
CopyRemoteCommitUrl = 'gitlens.copyRemoteCommitUrl',
CopyRemoteComparisonUrl = 'gitlens.copyRemoteComparisonUrl',
CopyRemoteFileUrl = 'gitlens.copyRemoteFileUrlToClipboard',
CopyRemoteFileUrlFrom = 'gitlens.copyRemoteFileUrlFrom',
CopyRemotePullRequestUrl = 'gitlens.copyRemotePullRequestUrl',
CopyRemoteRepositoryUrl = 'gitlens.copyRemoteRepositoryUrl',
CopyShaToClipboard = 'gitlens.copyShaToClipboard',
Expand Down Expand Up @@ -76,6 +77,7 @@ export enum Commands {
OpenComparisonOnRemote = 'gitlens.openComparisonOnRemote',
OpenFileFromRemote = 'gitlens.openFileFromRemote',
OpenFileOnRemote = 'gitlens.openFileOnRemote',
OpenFileOnRemoteFrom = 'gitlens.openFileOnRemoteFrom',
OpenFileAtRevision = 'gitlens.openFileRevision',
OpenFileAtRevisionFrom = 'gitlens.openFileRevisionFrom',
OpenOnRemote = 'gitlens.openOnRemote',
Expand Down
57 changes: 40 additions & 17 deletions src/commands/openFileOnRemote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,35 @@ import {
isCommandContextViewNodeHasCommit,
} from './common';
import { UriComparer } from '../comparers';
import { BranchSorting } from '../configuration';
import { BranchSorting, TagSorting } from '../configuration';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitRevision, RemoteResourceType } from '../git/git';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { ReferencePicker, ReferencesQuickPickIncludes } from '../quickpicks';
import { ReferencePicker } from '../quickpicks';
import { OpenOnRemoteCommandArgs } from './openOnRemote';
import { Strings } from '../system';
import { StatusFileNode } from '../views/nodes';

export interface OpenFileOnRemoteCommandArgs {
branch?: string;
branchOrTag?: string;
clipboard?: boolean;
range?: boolean;
sha?: string;
pickBranchOrTag?: boolean;
}

@command()
export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
constructor() {
super([Commands.OpenFileOnRemote, Commands.Deprecated_OpenFileInRemote, Commands.CopyRemoteFileUrl]);
super([
Commands.OpenFileOnRemote,
Commands.Deprecated_OpenFileInRemote,
Commands.CopyRemoteFileUrl,
Commands.OpenFileOnRemoteFrom,
Commands.CopyRemoteFileUrlFrom,
]);
}

protected async preExecute(context: CommandContext, args?: OpenFileOnRemoteCommandArgs) {
Expand All @@ -43,11 +50,11 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
} else if (isCommandContextViewNodeHasCommit(context)) {
args = { ...args, range: false };

if (context.command === Commands.CopyRemoteFileUrl) {
if (context.command === Commands.CopyRemoteFileUrl || context.command === Commands.CopyRemoteFileUrlFrom) {
// If it is a StatusFileNode then don't include the sha, since it hasn't been pushed yet
args.sha = context.node instanceof StatusFileNode ? undefined : context.node.commit.sha;
} else if (isCommandContextViewNodeHasBranch(context)) {
args.branch = context.node.branch?.name;
args.branchOrTag = context.node.branch?.name;
}

uri = context.node.uri;
Expand All @@ -57,7 +64,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
uri = context.node.uri ?? context.uri;
}

if (context.command === Commands.CopyRemoteFileUrl) {
if (context.command === Commands.CopyRemoteFileUrl || context.command === Commands.CopyRemoteFileUrlFrom) {
args = { ...args, clipboard: true };
if (args.sha == null) {
const uri = getCommandUri(context.uri, context.editor);
Expand All @@ -80,6 +87,10 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
}
}

if (context.command === Commands.OpenFileOnRemoteFrom || context.command === Commands.CopyRemoteFileUrlFrom) {
args = { ...args, pickBranchOrTag: true, range: false };
}

return this.execute(context.editor, uri, args);
}

Expand All @@ -105,45 +116,57 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
: undefined;
let sha = args.sha ?? gitUri.sha;

if (args.branch == null && sha != null && !GitRevision.isSha(sha) && remotes.length !== 0) {
if (args.branchOrTag == null && sha != null && !GitRevision.isSha(sha) && remotes.length !== 0) {
const [remoteName, branchName] = Strings.splitSingle(sha, '/');
if (branchName != null && remotes.some(r => r.name === remoteName)) {
args.branch = branchName;
args.branchOrTag = branchName;
sha = undefined;
}
}

if (args.branch == null && args.sha == null) {
const branch = await Container.git.getBranch(gitUri.repoPath);
if (branch == null || branch.tracking == null) {
if ((args.sha == null && args.branchOrTag == null) || args.pickBranchOrTag) {
let branch;
if (!args.pickBranchOrTag) {
branch = await Container.git.getBranch(gitUri.repoPath);
}

if (branch?.tracking == null) {
const pick = await ReferencePicker.show(
gitUri.repoPath,
args.clipboard
? `Copy Remote File Url From${Strings.pad(GlyphChars.Dot, 2, 2)}${gitUri.relativePath}`
: `Open File on Remote From${Strings.pad(GlyphChars.Dot, 2, 2)}${gitUri.relativePath}`,
`Choose a branch to ${args.clipboard ? 'copy' : 'open'} the file revision from`,
`Choose a branch or tag to ${args.clipboard ? 'copy' : 'open'} the file revision from`,
{
allowEnteringRefs: true,
autoPick: true,
// checkmarks: false,
filter: { branches: b => b.tracking != null },
include: ReferencesQuickPickIncludes.Branches,
picked: args.branchOrTag,
sort: {
branches: { current: true, orderBy: BranchSorting.DateDesc },
tags: { orderBy: TagSorting.DateDesc },
},
},
);
if (pick == null) return;

args.branch = pick.ref;
if (pick.refType === 'branch' || pick.refType === 'tag') {
args.branchOrTag = pick.ref;
sha = undefined;
} else {
args.branchOrTag = undefined;
sha = pick.ref;
}
} else {
args.branch = branch.name;
args.branchOrTag = branch.name;
}
}

void (await executeCommand<OpenOnRemoteCommandArgs>(Commands.OpenOnRemote, {
resource: {
type: sha == null ? RemoteResourceType.File : RemoteResourceType.Revision,
branch: args.branch ?? 'HEAD',
branchOrTag: args.branchOrTag ?? 'HEAD',
fileName: gitUri.relativePath,
range: range,
sha: sha ?? undefined,
Expand Down
8 changes: 4 additions & 4 deletions src/git/remotes/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type RemoteResource =
}
| {
type: RemoteResourceType.File;
branch?: string;
branchOrTag?: string;
fileName: string;
range?: Range;
}
Expand All @@ -60,7 +60,7 @@ export type RemoteResource =
}
| {
type: RemoteResourceType.Revision;
branch?: string;
branchOrTag?: string;
commit?: GitLogCommit;
fileName: string;
range?: Range;
Expand Down Expand Up @@ -167,7 +167,7 @@ export abstract class RemoteProvider {
return encodeURI(
this.getUrlForFile(
resource.fileName,
resource.branch != null ? resource.branch : undefined,
resource.branchOrTag != null ? resource.branchOrTag : undefined,
undefined,
resource.range,
),
Expand All @@ -178,7 +178,7 @@ export abstract class RemoteProvider {
return encodeURI(
this.getUrlForFile(
resource.fileName,
resource.branch != null ? resource.branch : undefined,
resource.branchOrTag != null ? resource.branchOrTag : undefined,
resource.sha != null ? resource.sha : undefined,
resource.range,
),
Expand Down
6 changes: 3 additions & 3 deletions src/webviews/apps/settings/partials/menus.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
data-setting-type="object"
disabled
/>
<label for="menus.editorTab.remote">Add <i>Open File on Remote</i> command</label>
<label for="menus.editorTab.remote">Add <i>Open File on Remote *</i> commands</label>
</div>
</div>

Expand Down Expand Up @@ -287,7 +287,7 @@
data-setting-type="object"
disabled
/>
<label for="menus.explorer.remote">Add <i>Open File on Remote</i> command</label>
<label for="menus.explorer.remote">Add <i>Open File on Remote *</i> commands</label>
</div>
</div>

Expand Down Expand Up @@ -487,7 +487,7 @@
data-setting-type="object"
disabled
/>
<label for="menus.scmItem.remote">Add <i>Open File on Remote</i> command</label>
<label for="menus.scmItem.remote">Add <i>Open File on Remote *</i> commands</label>
</div>
</div>

Expand Down

0 comments on commit a4b74d0

Please sign in to comment.