Kaynağa Gözat

Closes #1071 - adds branch or tag picking

main
Eric Amodio 4 yıl önce
ebeveyn
işleme
a4b74d0e3d
7 değiştirilmiş dosya ile 111 ekleme ve 29 silme
  1. +2
    -0
      CHANGELOG.md
  2. +3
    -1
      README.md
  3. +57
    -4
      package.json
  4. +2
    -0
      src/commands/common.ts
  5. +40
    -17
      src/commands/openFileOnRemote.ts
  6. +4
    -4
      src/git/remotes/provider.ts
  7. +3
    -3
      src/webviews/apps/settings/partials/menus.html

+ 2
- 0
CHANGELOG.md Dosyayı Görüntüle

@ -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

+ 3
- 1
README.md Dosyayı Görüntüle

@ -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
@ -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 |

+ 57
- 4
package.json Dosyayı Görüntüle

@ -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",
@ -3159,6 +3161,21 @@
}
},
{
"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...",
"icon": {
@ -4803,6 +4820,14 @@
"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/"
},
@ -5626,9 +5651,15 @@
"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",
@ -5792,9 +5823,15 @@
"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": [
@ -5810,9 +5847,15 @@
"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",
@ -5875,10 +5918,16 @@
{
"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",
"group": "navigation@99"
@ -7540,6 +7589,10 @@
{
"command": "gitlens.copyRemoteFileUrlToClipboard",
"group": "2_gitlens@4"
},
{
"command": "gitlens.copyRemoteFileUrlFrom",
"group": "2_gitlens@5"
}
],
"gitlens/editor/context/openChanges": [

+ 2
- 0
src/commands/common.ts Dosyayı Görüntüle

@ -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',
@ -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',

+ 40
- 17
src/commands/openFileOnRemote.ts Dosyayı Görüntüle

@ -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) {
@ -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;
@ -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);
@ -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);
}
@ -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,

+ 4
- 4
src/git/remotes/provider.ts Dosyayı Görüntüle

@ -51,7 +51,7 @@ export type RemoteResource =
}
| {
type: RemoteResourceType.File;
branch?: string;
branchOrTag?: string;
fileName: string;
range?: Range;
}
@ -60,7 +60,7 @@ export type RemoteResource =
}
| {
type: RemoteResourceType.Revision;
branch?: string;
branchOrTag?: string;
commit?: GitLogCommit;
fileName: string;
range?: Range;
@ -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,
),
@ -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,
),

+ 3
- 3
src/webviews/apps/settings/partials/menus.html Dosyayı Görüntüle

@ -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>
@ -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>
@ -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>

Yükleniyor…
İptal
Kaydet