Skip to content

Commit

Permalink
Fixes issues with external files over a Live Share session
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Dec 5, 2018
1 parent e07bc76 commit 857fb47
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Fixes [#565](https://github.com/eamodio/vscode-gitlens/issues/565) — Regression: Submodules don't work properly (missing repo in view, file and inline blame, etc)
- Fixes [#528](https://github.com/eamodio/vscode-gitlens/issues/528) — Remotes not showing, being filtred on domain and file, but not complete path
- Fixes an issue where _Close Repository_ command didn't work
- Fixes issues with external files (files not in one of the workspace folders) showing up as a new repository when over a Live Share session

## [9.0.1] - 2018-12-02

Expand Down
33 changes: 25 additions & 8 deletions src/git/gitService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1655,7 +1655,7 @@ export class GitService implements Disposable {
let repo = await this.getRepository(filePathOrUri, { ...options, skipCacheUpdate: true });
if (repo !== undefined) return repo.path;

let rp = await this.getRepoPathCore(
const rp = await this.getRepoPathCore(
typeof filePathOrUri === 'string' ? filePathOrUri : filePathOrUri.fsPath,
false
);
Expand All @@ -1664,8 +1664,11 @@ export class GitService implements Disposable {
// Recheck this._repositoryTree.get(rp) to make sure we haven't already tried adding this due to awaits
if (this._repositoryTree.get(rp) !== undefined) return rp;

const isVslsScheme =
typeof filePathOrUri === 'string' ? undefined : filePathOrUri.scheme === DocumentSchemes.Vsls;

// If this new repo is inside one of our known roots and we we don't already know about, add it
const root = this.findRepositoryForPath(this._repositoryTree, rp);
const root = this.findRepositoryForPath(this._repositoryTree, rp, isVslsScheme);

let folder;
if (root !== undefined) {
Expand All @@ -1674,10 +1677,14 @@ export class GitService implements Disposable {
folder = root.folder;
}
else {
folder = workspace.getWorkspaceFolder(GitUri.file(rp));
folder = workspace.getWorkspaceFolder(GitUri.file(rp, isVslsScheme));
if (folder === undefined) {
const parts = rp.split('/');
folder = { uri: GitUri.file(rp), name: parts[parts.length - 1], index: this._repositoryTree.count() };
folder = {
uri: GitUri.file(rp, isVslsScheme),
name: parts[parts.length - 1],
index: this._repositoryTree.count()
};
}
}

Expand Down Expand Up @@ -1757,12 +1764,15 @@ export class GitService implements Disposable {
): Promise<Repository | undefined> {
const repositoryTree = await this.getRepositoryTree();

let isVslsScheme;

let path: string;
if (typeof repoPathOrUri === 'string') {
const repo = repositoryTree.get(repoPathOrUri);
if (repo !== undefined) return repo;

path = repoPathOrUri;
isVslsScheme = undefined;
}
else {
if (repoPathOrUri instanceof GitUri) {
Expand All @@ -1776,22 +1786,29 @@ export class GitService implements Disposable {
else {
path = repoPathOrUri.fsPath;
}

isVslsScheme = repoPathOrUri.scheme === DocumentSchemes.Vsls;
}

const repo = this.findRepositoryForPath(repositoryTree, path);
const repo = this.findRepositoryForPath(repositoryTree, path, isVslsScheme);
if (repo === undefined) return undefined;

// Make sure the file is tracked in this repo before returning -- it could be from a submodule
if (!(await this.isTracked(path, repo.path, options))) return undefined;
return repo;
}

private findRepositoryForPath(repositoryTree: TernarySearchTree<Repository>, path: string): Repository | undefined {
private findRepositoryForPath(
repositoryTree: TernarySearchTree<Repository>,
path: string,
isVslsScheme: boolean | undefined
): Repository | undefined {
let repo = repositoryTree.findSubstr(path);
// If we can't find the repo and we are a guest, check if we are a "root" workspace
if (repo === undefined && Container.vsls.isMaybeGuest) {
if (repo === undefined && isVslsScheme !== false && Container.vsls.isMaybeGuest) {
if (!vslsUriPrefixRegex.test(path)) {
const vslsPath = Strings.normalizePath(`/~0${path}`);
path = Strings.normalizePath(path);
const vslsPath = `/~0${path[0] === '/' ? path : `/${path}`}`;
repo = repositoryTree.findSubstr(vslsPath);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/git/gitUri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ export class GitUri extends ((Uri as any) as UriEx) {
return [authority, fsPath];
}

static file(path: string) {
static file(path: string, useVslsScheme?: boolean) {
const uri = Uri.file(path);
if (Container.vsls.isMaybeGuest) {
if (Container.vsls.isMaybeGuest && useVslsScheme !== false) {
return uri.with({ scheme: DocumentSchemes.Vsls });
}

Expand Down
4 changes: 2 additions & 2 deletions src/vsls/vsls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Logger } from './../logger';
import { VslsGuestService } from './guest';
import { VslsHostService } from './host';

export const vslsUriPrefixRegex = /^[\/|\\]~\d+?(?:[\/|\\]|$)/;
export const vslsUriRootRegex = /^[\/|\\]~\d+?$/;
export const vslsUriPrefixRegex = /^[\/|\\]~(?:\d+?|external)(?:[\/|\\]|$)/;
export const vslsUriRootRegex = /^[\/|\\]~(?:\d+?|external)$/;

export class VslsController implements Disposable {
private _disposable: Disposable | undefined;
Expand Down

0 comments on commit 857fb47

Please sign in to comment.