diff --git a/src/git/gitContextTracker.ts b/src/git/gitContextTracker.ts index a31e4d2..594ec10 100644 --- a/src/git/gitContextTracker.ts +++ b/src/git/gitContextTracker.ts @@ -114,7 +114,7 @@ export class GitContextTracker extends Disposable { private async _updateContextHasRemotes(uri: GitUri | undefined) { try { let hasRemotes = false; - if (uri) { + if (uri && this.git.isTrackable(uri)) { const repoPath = uri.repoPath || this.git.repoPath; if (repoPath) { const remotes = await this.git.getRemotes(repoPath); diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index f051ca3..e974900 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -72,17 +72,19 @@ export class GitUri extends Uri { } getRelativePath(): string { - return GitService.normalizePath(path.relative(this.repoPath || '', this.fsPath)); + return GitService.normalizePath(path.relative(this.repoPath || '', this.fsPath)); } static async fromUri(uri: Uri, git: GitService) { if (uri instanceof GitUri) return uri; + if (!git.isTrackable(uri)) return new GitUri(uri, git.repoPath); + const gitUri = git.getGitUriForFile(uri.fsPath); if (gitUri) return gitUri; // If this is a git uri, assume it is showing the most recent commit - if (uri.scheme === 'git' && uri.query === '~') { + if (uri.scheme === DocumentSchemes.Git && uri.query === '~') { const commit = await git.getLogCommit(undefined, uri.fsPath); if (commit) return new GitUri(uri, commit); } diff --git a/src/gitService.ts b/src/gitService.ts index c1187e8..ee69485 100644 --- a/src/gitService.ts +++ b/src/gitService.ts @@ -306,7 +306,7 @@ export class GitService extends Disposable { const cacheKey = this.getCacheEntryKey(uri.fsPath); const entry = this._gitCache.get(cacheKey); - if (!entry) return await this.isTracked(uri); + if (entry === undefined) return await this.isTracked(uri); return !entry.hasErrors; } @@ -691,8 +691,8 @@ export class GitService extends Disposable { } async getRemotes(repoPath: string): Promise { - if (!this.config.insiders) return Promise.resolve([]); - if (!repoPath) return Promise.resolve([]); + if (!this.config.insiders) return []; + if (!repoPath) return []; Logger.log(`getRemotes('${repoPath}')`); @@ -790,10 +790,7 @@ export class GitService extends Disposable { } isEditorBlameable(editor: TextEditor): boolean { - return (editor.viewColumn !== undefined || - editor.document.uri.scheme === DocumentSchemes.File || - editor.document.uri.scheme === DocumentSchemes.Git || - this.hasGitUriForFile(editor)); + return (editor.viewColumn !== undefined || this.isTrackable(editor.document.uri) || this.hasGitUriForFile(editor)); } async isFileUncommitted(uri: GitUri): Promise { @@ -803,8 +800,16 @@ export class GitService extends Disposable { return !!status; } + isTrackable(uri: Uri): boolean { + // Logger.log(`isTrackable('${uri.scheme}', '${uri.fsPath}')`); + + return uri.scheme === DocumentSchemes.File || uri.scheme === DocumentSchemes.Git || uri.scheme === DocumentSchemes.GitLensGit; + } + async isTracked(uri: GitUri): Promise { - Logger.log(`isFileUncommitted('${uri.repoPath}', '${uri.fsPath}')`); + if (!this.isTrackable(uri)) return false; + + Logger.log(`isTracked('${uri.fsPath}', '${uri.repoPath}')`); const result = await Git.ls_files(uri.repoPath === undefined ? '' : uri.repoPath, uri.fsPath); return !!result;