diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 84099ff..8686a19 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -33,7 +33,7 @@ import { RepositoryInitWatcher, ScmRepository, } from '../../../git/gitProvider'; -import { GitProviderService } from '../../../git/gitProviderService'; +import { GitProviderDescriptor, GitProviderService } from '../../../git/gitProviderService'; import { GitUri } from '../../../git/gitUri'; import { BranchSortOptions, @@ -120,7 +120,14 @@ const mappedAuthorRegex = /(.+)\s<(.+)>/; const reflogCommands = ['merge', 'pull']; export class LocalGitProvider implements GitProvider, Disposable { - descriptor = { id: GitProviderId.Git, name: 'Git' }; + readonly descriptor: GitProviderDescriptor = { id: GitProviderId.Git, name: 'Git' }; + readonly supportedSchemes: string[] = [ + DocumentSchemes.File, + DocumentSchemes.Git, + DocumentSchemes.GitLens, + DocumentSchemes.PRs, + DocumentSchemes.Vsls, + ]; private _onDidChangeRepository = new EventEmitter(); get onDidChangeRepository(): Event { @@ -3415,14 +3422,7 @@ export class LocalGitProvider implements GitProvider, Disposable { } isTrackable(uri: Uri): boolean { - const { scheme } = uri; - return ( - scheme === DocumentSchemes.File || - scheme === DocumentSchemes.Git || - scheme === DocumentSchemes.GitLens || - scheme === DocumentSchemes.PRs || - scheme === DocumentSchemes.Vsls - ); + return this.supportedSchemes.includes(uri.scheme); } private async isTracked(filePath: string, repoPath?: string, ref?: string): Promise; diff --git a/src/git/gitProvider.ts b/src/git/gitProvider.ts index a145484..d69d934 100644 --- a/src/git/gitProvider.ts +++ b/src/git/gitProvider.ts @@ -68,6 +68,7 @@ export interface GitProvider { get onDidChangeRepository(): Event; readonly descriptor: GitProviderDescriptor; + readonly supportedSchemes: string[]; discoverRepositories(uri: Uri): Promise; createRepository( diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index 9dd196e..940eed8 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -99,6 +99,11 @@ export type RepositoriesChangeEvent = { readonly removed: readonly Repository[]; }; +export interface GitProviderResult { + provider: GitProvider; + path: string; +} + export class GitProviderService implements Disposable { private readonly _onDidChangeProviders = new EventEmitter(); get onDidChangeProviders(): Event { @@ -156,6 +161,7 @@ export class GitProviderService implements Disposable { private readonly _disposable: Disposable; private readonly _providers = new Map(); private readonly _repositories = new Map(); + private readonly _supportedSchemes = new Set(); constructor(private readonly container: Container) { this._disposable = Disposable.from( @@ -318,6 +324,9 @@ export class GitProviderService implements Disposable { if (this._providers.has(id)) throw new Error(`Provider '${id}' has already been registered`); this._providers.set(id, provider); + for (const scheme of provider.supportedSchemes) { + this._supportedSchemes.add(scheme); + } const disposables = []; @@ -550,7 +559,7 @@ export class GitProviderService implements Disposable { void updateRemoteContext.call(this); } - private getProvider(repoPath: string | Uri): { provider: GitProvider; path: string } { + private getProvider(repoPath: string | Uri): GitProviderResult { const id = GitProviderService.getProviderId(repoPath); const provider = this._providers.get(id); @@ -1720,6 +1729,9 @@ export class GitProviderService implements Disposable { } isTrackable(uri: Uri): boolean { + const { scheme } = uri; + if (!this._supportedSchemes.has(scheme)) return false; + const { provider } = this.getProvider(uri); return provider.isTrackable(uri); }