Bläddra i källkod

Fixes #695 - invalid url w/ remote in branch name

main
Eric Amodio 5 år sedan
förälder
incheckning
6158ff44eb
4 ändrade filer med 54 tillägg och 34 borttagningar
  1. +1
    -0
      CHANGELOG.md
  2. +39
    -25
      src/commands/openFileInRemote.ts
  3. +8
    -9
      src/commands/openInRemote.ts
  4. +6
    -0
      src/system/string.ts

+ 1
- 0
CHANGELOG.md Visa fil

@ -37,6 +37,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed
- Fixes [#695](https://github.com/eamodio/vscode-gitlens/issues/695) - Invalid URL in Open File in Remote when selecting origin/.. as comparison branch
- Fixes [#683](https://github.com/eamodio/vscode-gitlens/issues/683) - log.showSignature leads to stray files being displayed
- Fixes [#691](https://github.com/eamodio/vscode-gitlens/issues/691) - Auto-expand tree view on Swap Comparison
- Fixes the behavior of the _Open Line Changes with Previous Revision_ (`gitlens.diffLineWithPrevious`) command to follow the line history much better

+ 39
- 25
src/commands/openFileInRemote.ts Visa fil

@ -15,6 +15,8 @@ import {
isCommandViewContextWithCommit
} from './common';
import { OpenInRemoteCommandArgs } from './openInRemote';
import { Git } from '../git/git';
import { Strings } from '../system';
export interface OpenFileInRemoteCommandArgs {
branch?: string;
@ -54,30 +56,6 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
const gitUri = await GitUri.fromUri(uri);
if (!gitUri.repoPath) return undefined;
if (args.branch === undefined && args.sha === undefined) {
const branch = await Container.git.getBranch(gitUri.repoPath);
if (branch === undefined || branch.tracking === undefined) {
const pick = await new BranchesAndTagsQuickPick(gitUri.repoPath).show(
args.clipboard
? `Copy url for ${gitUri.getRelativePath()} to clipboard for which branch${GlyphChars.Ellipsis}`
: `Open ${gitUri.getRelativePath()} on remote for which branch${GlyphChars.Ellipsis}`,
{
autoPick: true,
filters: {
branches: b => b.tracking !== undefined
},
include: 'branches'
}
);
if (pick === undefined || pick instanceof CommandQuickPickItem) return undefined;
args.branch = pick.ref;
}
else {
args.branch = branch.name;
}
}
try {
const remotes = await Container.git.getRemotes(gitUri.repoPath);
const range =
@ -87,7 +65,43 @@ export class OpenFileInRemoteCommand extends ActiveEditorCommand {
editor.selection.end.with({ line: editor.selection.end.line + 1 })
)
: undefined;
const sha = args.sha || gitUri.sha;
let sha = args.sha || gitUri.sha;
if (args.branch === undefined && sha !== undefined && !Git.isSha(sha) && remotes.length !== 0) {
const [remotePart, branchPart] = Strings.splitSingle(sha, '/');
if (branchPart !== undefined) {
if (remotes.some(r => r.name === remotePart)) {
args.branch = branchPart;
sha = undefined;
}
}
}
if (args.branch === undefined && args.sha === undefined) {
const branch = await Container.git.getBranch(gitUri.repoPath);
if (branch === undefined || branch.tracking === undefined) {
const pick = await new BranchesAndTagsQuickPick(gitUri.repoPath).show(
args.clipboard
? `Copy url for ${gitUri.getRelativePath()} to clipboard for which branch${
GlyphChars.Ellipsis
}`
: `Open ${gitUri.getRelativePath()} on remote for which branch${GlyphChars.Ellipsis}`,
{
autoPick: true,
filters: {
branches: b => b.tracking !== undefined
},
include: 'branches'
}
);
if (pick === undefined || pick instanceof CommandQuickPickItem) return undefined;
args.branch = pick.ref;
}
else {
args.branch = branch.name;
}
}
const commandArgs: OpenInRemoteCommandArgs = {
resource:

+ 8
- 9
src/commands/openInRemote.ts Visa fil

@ -113,14 +113,13 @@ export class OpenInRemoteCommand extends ActiveEditorCommand {
if (args.remotes === undefined || args.resource === undefined || args.resource.type !== 'branch') return;
// Check to see if the remote is in the branch
const index = args.resource.branch.indexOf('/');
if (index >= 0) {
const remoteName = args.resource.branch.substring(0, index);
const remote = args.remotes.find(r => r.name === remoteName);
if (remote !== undefined) {
args.resource.branch = args.resource.branch.substring(index + 1);
args.remotes = [remote];
}
}
const [remotePart, branchPart] = Strings.splitSingle(args.resource.branch, '/');
if (branchPart === undefined) return;
const remote = args.remotes.find(r => r.name === remotePart);
if (remote === undefined) return;
args.resource.branch = branchPart;
args.remotes = [remote];
}
}

+ 6
- 0
src/system/string.ts Visa fil

@ -173,6 +173,12 @@ export namespace Strings {
.digest(encoding);
}
export function splitSingle(s: string, splitter: string) {
const parts = s.split(splitter, 1);
const first = parts[0];
return first.length === s.length ? parts : [first, s.substr(first.length + 1)];
}
export function truncate(s: string, truncateTo: number, ellipsis: string = '\u2026', width?: number) {
if (!s) return s;

Laddar…
Avbryt
Spara