From 1cecab43f5c6ba3920bb79d6f58127fff337a0ae Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 3 Oct 2017 13:01:59 -0400 Subject: [PATCH] Fixes `gitlens-git` file paths and blameability --- src/git/gitUri.ts | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index 87ab457..b741d76 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -5,7 +5,12 @@ import { DocumentSchemes, GlyphChars } from '../constants'; import { GitService, IGitStatusFile } from '../gitService'; import * as path from 'path'; -export class GitUri extends Uri { +interface UriEx { + new(): Uri; + new(scheme: string, authority: string, path: string, query: string, fragment: string): Uri; +} + +export class GitUri extends (Uri as UriEx) { offset: number; repoPath?: string | undefined; @@ -15,20 +20,14 @@ export class GitUri extends Uri { constructor(uri?: Uri, repoPath?: string); constructor(uri?: Uri, commitOrRepoPath?: IGitCommitInfo | string); constructor(uri?: Uri, commitOrRepoPath?: IGitCommitInfo | string) { - super(); - if (!uri) return; - - const base = this as any; - for (const key in uri) { - if (uri.hasOwnProperty(key)) { - base[key] = (uri as any)[key]; - } + if (uri === undefined) { + super(); + return; } - this.offset = 0; if (uri.scheme === DocumentSchemes.GitLensGit) { const data = GitService.fromGitContentUri(uri); - base._fsPath = path.resolve(data.repoPath, data.originalFileName || data.fileName); + super(uri.scheme, uri.authority, path.resolve(data.repoPath, data.originalFileName || data.fileName), uri.query, uri.fragment); this.offset = (data.decoration && data.decoration.split('\n').length) || 0; if (!GitService.isUncommitted(data.sha)) { @@ -38,12 +37,16 @@ export class GitUri extends Uri { } else if (commitOrRepoPath) { if (typeof commitOrRepoPath === 'string') { + super(uri.scheme, uri.authority, uri.path, uri.query, uri.fragment); + + this.offset = 0; this.repoPath = commitOrRepoPath; } else { const commit = commitOrRepoPath; - base._fsPath = path.resolve(commit.repoPath, commit.originalFileName || commit.fileName || ''); + super(uri.scheme, uri.authority, path.resolve(commit.repoPath, commit.originalFileName || commit.fileName || ''), uri.query, uri.fragment); + this.offset = 0; if (commit.repoPath !== undefined) { this.repoPath = commit.repoPath; } @@ -91,6 +94,8 @@ export class GitUri extends Uri { if (!git.isTrackable(uri)) return new GitUri(uri, git.repoPath); + if (uri.scheme === DocumentSchemes.GitLensGit) return new GitUri(uri); + // If this is a git uri, assume it is showing the most recent commit if (uri.scheme === DocumentSchemes.Git) { const commit = await git.getLogCommit(undefined, uri.fsPath);