Skip to content

Commit 2661440

Browse files
committed
Avoids caching when unable to detect repo changes - closes #583
1 parent 2c5b667 commit 2661440

File tree

3 files changed

+40
-9
lines changed

3 files changed

+40
-9
lines changed

src/git/gitService.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,10 @@ export class GitService implements Disposable {
10881088
branches = GitBranchParser.parse(data, repoPath) || [];
10891089
}
10901090

1091-
this._branchesCache.set(repoPath, branches);
1091+
const repo = await this.getRepository(repoPath);
1092+
if (repo !== undefined && repo.supportsChangeEvents) {
1093+
this._branchesCache.set(repoPath, branches);
1094+
}
10921095
return branches;
10931096
}
10941097

@@ -1897,7 +1900,12 @@ export class GitService implements Disposable {
18971900

18981901
const data = await Git.showref_tag(repoPath);
18991902
tags = GitTagParser.parseWithRef(data, repoPath) || [];
1900-
this._tagsWithRefsCache.set(repoPath, tags);
1903+
1904+
const repo = await this.getRepository(repoPath);
1905+
if (repo !== undefined && repo.supportsChangeEvents) {
1906+
this._tagsWithRefsCache.set(repoPath, tags);
1907+
}
1908+
19011909
return tags;
19021910
}
19031911

@@ -1906,7 +1914,12 @@ export class GitService implements Disposable {
19061914

19071915
const data = await Git.tag(repoPath);
19081916
tags = GitTagParser.parse(data, repoPath) || [];
1909-
this._tagsCache.set(repoPath, tags);
1917+
1918+
const repo = await this.getRepository(repoPath);
1919+
if (repo !== undefined && repo.supportsChangeEvents) {
1920+
this._tagsCache.set(repoPath, tags);
1921+
}
1922+
19101923
return tags;
19111924
}
19121925

src/git/models/repository.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class Repository implements Disposable {
7474
readonly index: number;
7575
readonly name: string;
7676
readonly normalizedPath: string;
77+
readonly supportsChangeEvents: boolean = true;
7778

7879
private _branch: Promise<GitBranch | undefined> | undefined;
7980
private readonly _disposable: Disposable;
@@ -94,22 +95,32 @@ export class Repository implements Disposable {
9495
suspended: boolean,
9596
closed: boolean = false
9697
) {
98+
const relativePath = paths.relative(folder.uri.fsPath, path);
9799
if (root) {
98-
this.formattedName = folder.name;
100+
// Check if the repository is not contained by a workspace folder
101+
const repoFolder = workspace.getWorkspaceFolder(GitUri.fromRepoPath(path));
102+
if (repoFolder === undefined) {
103+
// If it isn't within a workspace folder we can't get change events, see: https://github.com/Microsoft/vscode/issues/3025
104+
this.supportsChangeEvents = false;
105+
this.formattedName = this.name = paths.basename(path);
106+
}
107+
else {
108+
this.formattedName = this.name = folder.name;
109+
}
99110
}
100111
else {
101-
const relativePath = paths.relative(folder.uri.fsPath, path);
102112
this.formattedName = relativePath ? `${folder.name} (${relativePath})` : folder.name;
113+
this.name = folder.name;
103114
}
104115
this.index = folder.index;
105-
this.name = folder.name;
106116

107-
this.normalizedPath = (this.path.endsWith('/') ? this.path : `${this.path}/`).toLowerCase();
117+
this.normalizedPath = (path.endsWith('/') ? path : `${path}/`).toLowerCase();
108118

109119
this._suspended = suspended;
110120
this._closed = closed;
111121

112122
// TODO: createFileSystemWatcher doesn't work unless the folder is part of the workspaceFolders
123+
// https://github.com/Microsoft/vscode/issues/3025
113124
const watcher = workspace.createFileSystemWatcher(
114125
new RelativePattern(
115126
folder,
@@ -241,11 +252,12 @@ export class Repository implements Disposable {
241252

242253
private async fetchCore(options: { remote?: string } = {}) {
243254
await Container.git.fetch(this.path, options.remote);
255+
244256
this.fireChange(RepositoryChange.Repository);
245257
}
246258

247259
getBranch(): Promise<GitBranch | undefined> {
248-
if (this._branch === undefined) {
260+
if (this._branch === undefined || !this.supportsChangeEvents) {
249261
this._branch = Container.git.getBranch(this.path);
250262
}
251263
return this._branch;
@@ -269,7 +281,7 @@ export class Repository implements Disposable {
269281
}
270282

271283
getRemotes(): Promise<GitRemote[]> {
272-
if (this._remotes === undefined) {
284+
if (this._remotes === undefined || !this.supportsChangeEvents) {
273285
if (this._providers === undefined) {
274286
const remotesCfg = configuration.get<RemotesConfig[] | null | undefined>(
275287
configuration.name('remotes').value,
@@ -371,6 +383,7 @@ export class Repository implements Disposable {
371383
if (this._fsWatcherDisposable !== undefined) return;
372384

373385
// TODO: createFileSystemWatcher doesn't work unless the folder is part of the workspaceFolders
386+
// https://github.com/Microsoft/vscode/issues/3025
374387
const watcher = workspace.createFileSystemWatcher(new RelativePattern(this.folder, `**`));
375388
this._fsWatcherDisposable = Disposable.from(
376389
watcher,

src/views/nodes/repositoryNode.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ export class RepositoryNode extends SubscribeableViewNode<RepositoriesView> {
150150
}
151151
}
152152

153+
if (!this.repo.supportsChangeEvents) {
154+
description = `<!>${description ? ` ${GlyphChars.Space}${description}` : ''}`;
155+
tooltip += `\n\n<!> Unable to automatically detect repository changes`;
156+
}
157+
153158
const item = new TreeItem(label, TreeItemCollapsibleState.Expanded);
154159
item.contextValue = ResourceType.Repository;
155160
item.description = `${description || ''}${this.formatLastFetched({

0 commit comments

Comments
 (0)