Skip to content

Commit 857fb47

Browse files
committed
Fixes issues with external files over a Live Share session
1 parent e07bc76 commit 857fb47

File tree

4 files changed

+30
-12
lines changed

4 files changed

+30
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1919
- 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)
2020
- Fixes [#528](https://github.com/eamodio/vscode-gitlens/issues/528) — Remotes not showing, being filtred on domain and file, but not complete path
2121
- Fixes an issue where _Close Repository_ command didn't work
22+
- 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
2223

2324
## [9.0.1] - 2018-12-02
2425

src/git/gitService.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ export class GitService implements Disposable {
16551655
let repo = await this.getRepository(filePathOrUri, { ...options, skipCacheUpdate: true });
16561656
if (repo !== undefined) return repo.path;
16571657

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

1667+
const isVslsScheme =
1668+
typeof filePathOrUri === 'string' ? undefined : filePathOrUri.scheme === DocumentSchemes.Vsls;
1669+
16671670
// If this new repo is inside one of our known roots and we we don't already know about, add it
1668-
const root = this.findRepositoryForPath(this._repositoryTree, rp);
1671+
const root = this.findRepositoryForPath(this._repositoryTree, rp, isVslsScheme);
16691672

16701673
let folder;
16711674
if (root !== undefined) {
@@ -1674,10 +1677,14 @@ export class GitService implements Disposable {
16741677
folder = root.folder;
16751678
}
16761679
else {
1677-
folder = workspace.getWorkspaceFolder(GitUri.file(rp));
1680+
folder = workspace.getWorkspaceFolder(GitUri.file(rp, isVslsScheme));
16781681
if (folder === undefined) {
16791682
const parts = rp.split('/');
1680-
folder = { uri: GitUri.file(rp), name: parts[parts.length - 1], index: this._repositoryTree.count() };
1683+
folder = {
1684+
uri: GitUri.file(rp, isVslsScheme),
1685+
name: parts[parts.length - 1],
1686+
index: this._repositoryTree.count()
1687+
};
16811688
}
16821689
}
16831690

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

1767+
let isVslsScheme;
1768+
17601769
let path: string;
17611770
if (typeof repoPathOrUri === 'string') {
17621771
const repo = repositoryTree.get(repoPathOrUri);
17631772
if (repo !== undefined) return repo;
17641773

17651774
path = repoPathOrUri;
1775+
isVslsScheme = undefined;
17661776
}
17671777
else {
17681778
if (repoPathOrUri instanceof GitUri) {
@@ -1776,22 +1786,29 @@ export class GitService implements Disposable {
17761786
else {
17771787
path = repoPathOrUri.fsPath;
17781788
}
1789+
1790+
isVslsScheme = repoPathOrUri.scheme === DocumentSchemes.Vsls;
17791791
}
17801792

1781-
const repo = this.findRepositoryForPath(repositoryTree, path);
1793+
const repo = this.findRepositoryForPath(repositoryTree, path, isVslsScheme);
17821794
if (repo === undefined) return undefined;
17831795

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

1789-
private findRepositoryForPath(repositoryTree: TernarySearchTree<Repository>, path: string): Repository | undefined {
1801+
private findRepositoryForPath(
1802+
repositoryTree: TernarySearchTree<Repository>,
1803+
path: string,
1804+
isVslsScheme: boolean | undefined
1805+
): Repository | undefined {
17901806
let repo = repositoryTree.findSubstr(path);
17911807
// If we can't find the repo and we are a guest, check if we are a "root" workspace
1792-
if (repo === undefined && Container.vsls.isMaybeGuest) {
1808+
if (repo === undefined && isVslsScheme !== false && Container.vsls.isMaybeGuest) {
17931809
if (!vslsUriPrefixRegex.test(path)) {
1794-
const vslsPath = Strings.normalizePath(`/~0${path}`);
1810+
path = Strings.normalizePath(path);
1811+
const vslsPath = `/~0${path[0] === '/' ? path : `/${path}`}`;
17951812
repo = repositoryTree.findSubstr(vslsPath);
17961813
}
17971814
}

src/git/gitUri.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ export class GitUri extends ((Uri as any) as UriEx) {
195195
return [authority, fsPath];
196196
}
197197

198-
static file(path: string) {
198+
static file(path: string, useVslsScheme?: boolean) {
199199
const uri = Uri.file(path);
200-
if (Container.vsls.isMaybeGuest) {
200+
if (Container.vsls.isMaybeGuest && useVslsScheme !== false) {
201201
return uri.with({ scheme: DocumentSchemes.Vsls });
202202
}
203203

src/vsls/vsls.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { Logger } from './../logger';
77
import { VslsGuestService } from './guest';
88
import { VslsHostService } from './host';
99

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

1313
export class VslsController implements Disposable {
1414
private _disposable: Disposable | undefined;

0 commit comments

Comments
 (0)