Skip to content

Commit

Permalink
Fixes #1447 - adds remote branch support
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Mar 29, 2021
1 parent 8bad710 commit 2b8a300
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Fixed

- Fixes [1447](https://github.com/eamodio/vscode-gitlens/issues/1447) - _Open File on Remote From..._ is missing remote branches
- Fixes [1442](https://github.com/eamodio/vscode-gitlens/issues/1442) - Interactive Rebase Editor not opened but plain text file when called from terminal
- Fixes [1439](https://github.com/eamodio/vscode-gitlens/issues/1439) - Copying a remote file URL for a file on Azure DevOps does not work — thanks to [PR #1440](https://github.com/eamodio/vscode-gitlens/pull/1440) by Lee C. ([MeltingMosaic](https://github.com/MeltingMosaic))
- Fixes [1445](https://github.com/eamodio/vscode-gitlens/issues/1439) - Improve documentation for hiding default added editor actions
Expand Down
29 changes: 22 additions & 7 deletions src/commands/openFileOnRemote.ts
Expand Up @@ -14,7 +14,7 @@ import { UriComparer } from '../comparers';
import { BranchSorting, TagSorting } from '../configuration';
import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitRevision, RemoteResourceType } from '../git/git';
import { GitBranch, GitRevision, RemoteResourceType } from '../git/git';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { ReferencePicker } from '../quickpicks';
Expand Down Expand Up @@ -106,7 +106,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
args = { range: true, ...args };

try {
const remotes = await Container.git.getRemotes(gitUri.repoPath);
let remotes = await Container.git.getRemotes(gitUri.repoPath);
const range =
args.range && editor != null && UriComparer.equals(editor.document.uri, uri)
? new Range(
Expand All @@ -120,9 +120,14 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {

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.branchOrTag = branchName;
sha = undefined;
if (branchName != null) {
const remote = remotes.find(r => r.name === remoteName);
if (remote != null) {
args.branchOrTag = branchName;
sha = undefined;

remotes = [remote];
}
}
}

Expand All @@ -143,7 +148,7 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
allowEnteringRefs: true,
autoPick: true,
// checkmarks: false,
filter: { branches: b => b.tracking != null },
filter: { branches: b => b.remote || b.tracking != null },
picked: args.branchOrTag,
sort: {
branches: { current: true, orderBy: BranchSorting.DateDesc },
Expand All @@ -153,7 +158,17 @@ export class OpenFileOnRemoteCommand extends ActiveEditorCommand {
);
if (pick == null) return;

if (pick.refType === 'branch' || pick.refType === 'tag') {
if (pick.refType === 'branch') {
if (pick.remote) {
const remoteName = GitBranch.getRemote(pick.name);
const remote = remotes.find(r => r.name === remoteName);
if (remote != null) {
remotes = [remote];
}
}
args.branchOrTag = pick.remote ? GitBranch.getNameWithoutRemote(pick.name) : pick.name;
sha = undefined;
} else if (pick.refType === 'tag') {
args.branchOrTag = pick.ref;
sha = undefined;
} else {
Expand Down

0 comments on commit 2b8a300

Please sign in to comment.