diff --git a/src/commands/common.ts b/src/commands/common.ts index d208333..7737206 100644 --- a/src/commands/common.ts +++ b/src/commands/common.ts @@ -253,7 +253,7 @@ export async function getRepoPathOrActiveOrPrompt(uri: Uri | undefined, editor: export async function getRepoPathOrPrompt(title: string, uri?: Uri) { if (uri == null) return Container.instance.git.highlander?.path; - const repoPath = (await Container.instance.git.getOrCreateRepository(uri))?.path; + const repoPath = (await Container.instance.git.getOrOpenRepository(uri))?.path; if (repoPath) return repoPath; const pick = await RepositoryPicker.show(title); diff --git a/src/commands/externalDiff.ts b/src/commands/externalDiff.ts index 574c975..b2444c5 100644 --- a/src/commands/externalDiff.ts +++ b/src/commands/externalDiff.ts @@ -150,7 +150,7 @@ export class ExternalDiffCommand extends Command { args.files.push({ uri: status.uri, staged: false }); } } else { - repoPath = (await this.container.git.getOrCreateRepository(args.files[0].uri))?.path; + repoPath = (await this.container.git.getOrOpenRepository(args.files[0].uri))?.path; if (!repoPath) return; } diff --git a/src/commands/git/coauthors.ts b/src/commands/git/coauthors.ts index e2ae768..77a08c8 100644 --- a/src/commands/git/coauthors.ts +++ b/src/commands/git/coauthors.ts @@ -110,7 +110,7 @@ export class CoAuthorsGitCommand extends QuickCommand { ); // Ensure that the active repo is known to the built-in git - context.activeRepo = await this.container.git.getOrCreateRepositoryForEditor(); + context.activeRepo = await this.container.git.getOrOpenRepositoryForEditor(); if ( context.activeRepo != null && !scmRepositories.some(r => r.rootUri.fsPath === context.activeRepo!.path) diff --git a/src/commands/quickCommand.steps.ts b/src/commands/quickCommand.steps.ts index 5b2eee0..ca89ee5 100644 --- a/src/commands/quickCommand.steps.ts +++ b/src/commands/quickCommand.steps.ts @@ -1131,7 +1131,7 @@ export async function* pickRepositoryStep< state.repo = Container.instance.git.getRepository(state.repo); if (state.repo != null) return state.repo; } - const active = state.repo ?? (await Container.instance.git.getOrCreateRepositoryForEditor()); + const active = state.repo ?? (await Container.instance.git.getOrOpenRepositoryForEditor()); const step = QuickCommand.createPickStep({ title: context.title, @@ -1194,7 +1194,7 @@ export async function* pickRepositoriesStep< actives = state.repos; } } else { - const active = await Container.instance.git.getOrCreateRepositoryForEditor(); + const active = await Container.instance.git.getOrOpenRepositoryForEditor(); actives = active != null ? [active] : []; } diff --git a/src/commands/stashSave.ts b/src/commands/stashSave.ts index 108d86d..b1870fa 100644 --- a/src/commands/stashSave.ts +++ b/src/commands/stashSave.ts @@ -42,7 +42,7 @@ export class StashSaveCommand extends Command { } else if (context.type === 'scm-states') { args = { ...args }; args.uris = context.scmResourceStates.map(s => s.resourceUri); - args.repoPath = (await this.container.git.getOrCreateRepository(args.uris[0]))?.path; + args.repoPath = (await this.container.git.getOrOpenRepository(args.uris[0]))?.path; const status = await this.container.git.getStatusForRepo(args.repoPath); if (status?.computeWorkingTreeStatus().staged) { @@ -60,7 +60,7 @@ export class StashSaveCommand extends Command { (a, b) => a.concat(b.resourceStates.map(s => s.resourceUri)), [], ); - args.repoPath = (await this.container.git.getOrCreateRepository(args.uris[0]))?.path; + args.repoPath = (await this.container.git.getOrOpenRepository(args.uris[0]))?.path; const status = await this.container.git.getStatusForRepo(args.repoPath); if (status?.computeWorkingTreeStatus().staged) { diff --git a/src/env/node/git/localGitProvider.ts b/src/env/node/git/localGitProvider.ts index 691a7c9..446ca75 100644 --- a/src/env/node/git/localGitProvider.ts +++ b/src/env/node/git/localGitProvider.ts @@ -338,7 +338,7 @@ export class LocalGitProvider implements GitProvider, Disposable { } } - createRepository( + openRepository( folder: WorkspaceFolder, uri: Uri, root: boolean, @@ -358,7 +358,7 @@ export class LocalGitProvider implements GitProvider, Disposable { ); } - createRepositoryInitWatcher(): RepositoryInitWatcher { + openRepositoryInitWatcher(): RepositoryInitWatcher { const watcher = workspace.createFileSystemWatcher('**/.git', false, true, true); return { onDidCreate: watcher.onDidCreate, @@ -386,7 +386,7 @@ export class LocalGitProvider implements GitProvider, Disposable { const uri = await this.findRepositoryUri(folder.uri, true); if (uri != null) { Logger.log(cc, `found root repository in '${uri.fsPath}'`); - repositories.push(this.createRepository(folder, uri, true)); + repositories.push(this.openRepository(folder, uri, true)); } if (depth <= 0) return repositories; @@ -443,7 +443,7 @@ export class LocalGitProvider implements GitProvider, Disposable { if (rp == null) continue; Logger.log(cc, `found repository in '${rp.fsPath}'`); - repositories.push(this.createRepository(folder, rp, false)); + repositories.push(this.openRepository(folder, rp, false)); } return repositories; @@ -3363,7 +3363,7 @@ export class LocalGitProvider implements GitProvider, Disposable { // If we didn't find it, check it as close to the file as possible (will find nested repos) tracked = Boolean(await Git.ls_files(newRepoPath, newRelativePath)); if (tracked) { - repository = await this.container.git.getOrCreateRepository(Uri.file(path), true); + repository = await this.container.git.getOrOpenRepository(Uri.file(path), true); if (repository != null) { return splitPath(path, repository.path); } @@ -3388,7 +3388,7 @@ export class LocalGitProvider implements GitProvider, Disposable { const index = relativePath.indexOf('/'); if (index < 0 || index === relativePath.length - 1) return undefined; - const nested = await this.container.git.getOrCreateRepository(Uri.file(path), true); + const nested = await this.container.git.getOrOpenRepository(Uri.file(path), true); if (nested != null && nested !== repository) { [relativePath, repoPath] = splitPath(path, repository.path); repository = undefined; diff --git a/src/git/gitProvider.ts b/src/git/gitProvider.ts index 2bff633..2c9d98a 100644 --- a/src/git/gitProvider.ts +++ b/src/git/gitProvider.ts @@ -82,14 +82,8 @@ export interface GitProvider extends Disposable { discoverRepositories(uri: Uri): Promise; updateContext?(): void; - createRepository( - folder: WorkspaceFolder, - uri: Uri, - root: boolean, - suspended?: boolean, - closed?: boolean, - ): Repository; - createRepositoryInitWatcher?(): RepositoryInitWatcher; + openRepository(folder: WorkspaceFolder, uri: Uri, root: boolean, suspended?: boolean, closed?: boolean): Repository; + openRepositoryInitWatcher?(): RepositoryInitWatcher; getOpenScmRepositories(): Promise; getOrOpenScmRepository(repoPath: string): Promise; diff --git a/src/git/gitProviderService.ts b/src/git/gitProviderService.ts index bb9ff92..36f7701 100644 --- a/src/git/gitProviderService.ts +++ b/src/git/gitProviderService.ts @@ -294,7 +294,7 @@ export class GitProviderService implements Disposable { const disposables = []; - const watcher = provider.createRepositoryInitWatcher?.(); + const watcher = provider.openRepositoryInitWatcher?.(); if (watcher != null) { disposables.push( watcher, @@ -331,7 +331,7 @@ export class GitProviderService implements Disposable { if (repository != null) { repository.closed = false; } else { - void this.getOrCreateRepository(e.uri); + void this.getOrOpenRepository(e.uri); } }), ); @@ -1424,8 +1424,8 @@ export class GitProviderService implements Disposable { private _pendingRepositories = new Map>(); - @log({ exit: r => `returned ${r?.path}` }) - async getOrCreateRepository(uri: Uri, detectNested?: boolean): Promise { + @log({ exit: r => `returned ${r?.path}` }) + async getOrOpenRepository(uri: Uri, detectNested?: boolean): Promise { const cc = Logger.getCorrelationContext(); const folderPath = dirname(uri.fsPath); @@ -1480,7 +1480,7 @@ export class GitProviderService implements Disposable { } Logger.log(cc, `Repository found in '${repoUri.toString(false)}'`); - repository = provider.createRepository(folder, repoUri, false); + repository = provider.openRepository(folder, repoUri, false); this._repositories.add(repository); this._pendingRepositories.delete(key); @@ -1499,15 +1499,15 @@ export class GitProviderService implements Disposable { return promise; } - @log({ + @log({ args: { 0: e => (e != null ? `TextEditor(${Logger.toLoggable(e.document.uri)})` : undefined) }, }) - async getOrCreateRepositoryForEditor(editor?: TextEditor): Promise { + async getOrOpenRepositoryForEditor(editor?: TextEditor): Promise { editor = editor ?? window.activeTextEditor; if (editor == null) return this.highlander; - return this.getOrCreateRepository(editor.document.uri); + return this.getOrOpenRepository(editor.document.uri); } getRepository(uri: Uri): Repository | undefined; diff --git a/src/git/gitUri.ts b/src/git/gitUri.ts index 274589e..9c54997 100644 --- a/src/git/gitUri.ts +++ b/src/git/gitUri.ts @@ -262,7 +262,7 @@ export class GitUri extends (Uri as any as UriEx) { } catch {} if (data?.path) { - const repository = await Container.instance.git.getOrCreateRepository(Uri.file(data.path)); + const repository = await Container.instance.git.getOrOpenRepository(Uri.file(data.path)); if (repository == null) { debugger; throw new Error(`Unable to find repository for uri=${uri.toString(false)}`); @@ -310,7 +310,7 @@ export class GitUri extends (Uri as any as UriEx) { } catch {} if (data?.fileName) { - const repository = await Container.instance.git.getOrCreateRepository(Uri.file(data.fileName)); + const repository = await Container.instance.git.getOrOpenRepository(Uri.file(data.fileName)); if (repository == null) { debugger; throw new Error(`Unable to find repository for uri=${uri.toString(false)}`); @@ -321,7 +321,7 @@ export class GitUri extends (Uri as any as UriEx) { repoPath = repoPath.substr(0, repoPath.length - data.fileName.length - 1); } else { // eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain - repoPath = (await Container.instance.git.getOrCreateRepository(uri))?.path!; + repoPath = (await Container.instance.git.getOrOpenRepository(uri))?.path!; if (!repoPath) { debugger; } @@ -336,7 +336,7 @@ export class GitUri extends (Uri as any as UriEx) { } } - const repository = await Container.instance.git.getOrCreateRepository(uri); + const repository = await Container.instance.git.getOrOpenRepository(uri); return new GitUri(uri, repository?.path); }