Browse Source

Fixes #208 - UNC paths fail

main
Eric Amodio 7 years ago
parent
commit
893a9afe44
2 changed files with 42 additions and 4 deletions
  1. +7
    -0
      CHANGELOG.md
  2. +35
    -4
      src/git/gitUri.ts

+ 7
- 0
CHANGELOG.md View File

@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Changed
- Improves startup performance and reduces package size
### Fixed
- Fixes [#208](https://github.com/eamodio/vscode-gitlens/issues/208) - Gitlens doesn't work over UNC
## [7.1.0] - 2017-12-22
### Added
- Adds `Open Working File` command (`gitlens.openWorkingFile`) - opens the working file for the active file revision -- closes [#236](https://github.com/eamodio/vscode-gitlens/issues/236)

+ 35
- 4
src/git/gitUri.ts View File

@ -11,9 +11,20 @@ export interface IGitCommitInfo {
sha?: string;
}
// Taken from https://github.com/Microsoft/vscode/blob/master/src/vs/base/common/uri.ts#L331-L337
interface UriComponents {
scheme: string;
authority: string;
path: string;
query: string;
fragment: string;
}
interface UriEx {
new(): Uri;
new(scheme: string, authority: string, path: string, query: string, fragment: string): Uri;
// Use this ctor, because vscode doesn't validate it
new(components: UriComponents): Uri;
}
export class GitUri extends ((Uri as any) as UriEx) {
@ -33,7 +44,9 @@ export class GitUri extends ((Uri as any) as UriEx) {
if (uri.scheme === DocumentSchemes.GitLensGit) {
const data: IUriRevisionData = JSON.parse(uri.query);
super(uri.scheme, uri.authority, path.resolve(data.repoPath, data.fileName), uri.query, uri.fragment);
const [authority, fsPath] = GitUri.ensureValidUNCPath(uri.authority, path.resolve(data.repoPath, data.fileName));
super({ scheme: uri.scheme, authority: authority, path: fsPath, query: uri.query, fragment: uri.fragment });
this.repoPath = data.repoPath;
if (GitService.isStagedUncommitted(data.sha) || !GitService.isUncommitted(data.sha)) {
@ -44,20 +57,21 @@ export class GitUri extends ((Uri as any) as UriEx) {
}
if (commitOrRepoPath === undefined) {
super(uri.scheme, uri.authority, uri.path, uri.query, uri.fragment);
super(uri);
return;
}
if (typeof commitOrRepoPath === 'string') {
super(uri.scheme, uri.authority, uri.path, uri.query, uri.fragment);
super(uri);
this.repoPath = commitOrRepoPath;
return;
}
super(uri.scheme, uri.authority, path.resolve(commitOrRepoPath.repoPath, commitOrRepoPath.fileName || uri.fsPath), uri.query, uri.fragment);
const [authority, fsPath] = GitUri.ensureValidUNCPath(uri.authority, path.resolve(commitOrRepoPath.repoPath, commitOrRepoPath.fileName || uri.fsPath));
super({ scheme: uri.scheme, authority: authority, path: fsPath, query: uri.query, fragment: uri.fragment });
this.repoPath = commitOrRepoPath.repoPath;
if (GitService.isStagedUncommitted(commitOrRepoPath.sha) || !GitService.isUncommitted(commitOrRepoPath.sha)) {
@ -96,6 +110,23 @@ export class GitUri extends ((Uri as any) as UriEx) {
return GitService.normalizePath(relativePath);
}
private static ensureValidUNCPath(authority: string, fsPath: string): [string, string] {
// Taken from https://github.com/Microsoft/vscode/blob/master/src/vs/base/common/uri.ts#L239-L251
// check for authority as used in UNC shares or use the path as given
if (fsPath[0] === '\\' && fsPath[1] === '\\') {
const index = fsPath.indexOf('\\', 2);
if (index === -1) {
authority = fsPath.substring(2);
fsPath = '\\';
} else {
authority = fsPath.substring(2, index);
fsPath = fsPath.substring(index) || '\\';
}
}
return [authority, fsPath];
}
static fromCommit(commit: GitCommit, previous: boolean = false) {
if (!previous) return new GitUri(commit.uri, commit);

Loading…
Cancel
Save