Browse Source

Renames repo create to open

main
Eric Amodio 2 years ago
parent
commit
9282c3a7fd
9 changed files with 27 additions and 33 deletions
  1. +1
    -1
      src/commands/common.ts
  2. +1
    -1
      src/commands/externalDiff.ts
  3. +1
    -1
      src/commands/git/coauthors.ts
  4. +2
    -2
      src/commands/quickCommand.steps.ts
  5. +2
    -2
      src/commands/stashSave.ts
  6. +6
    -6
      src/env/node/git/localGitProvider.ts
  7. +2
    -8
      src/git/gitProvider.ts
  8. +8
    -8
      src/git/gitProviderService.ts
  9. +4
    -4
      src/git/gitUri.ts

+ 1
- 1
src/commands/common.ts View File

@ -253,7 +253,7 @@ export async function getRepoPathOrActiveOrPrompt(uri: Uri | undefined, editor:
export async function getRepoPathOrPrompt(title: string, uri?: Uri) { export async function getRepoPathOrPrompt(title: string, uri?: Uri) {
if (uri == null) return Container.instance.git.highlander?.path; 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; if (repoPath) return repoPath;
const pick = await RepositoryPicker.show(title); const pick = await RepositoryPicker.show(title);

+ 1
- 1
src/commands/externalDiff.ts View File

@ -150,7 +150,7 @@ export class ExternalDiffCommand extends Command {
args.files.push({ uri: status.uri, staged: false }); args.files.push({ uri: status.uri, staged: false });
} }
} else { } 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; if (!repoPath) return;
} }

+ 1
- 1
src/commands/git/coauthors.ts View File

@ -110,7 +110,7 @@ export class CoAuthorsGitCommand extends QuickCommand {
); );
// Ensure that the active repo is known to the built-in git // 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 ( if (
context.activeRepo != null && context.activeRepo != null &&
!scmRepositories.some(r => r.rootUri.fsPath === context.activeRepo!.path) !scmRepositories.some(r => r.rootUri.fsPath === context.activeRepo!.path)

+ 2
- 2
src/commands/quickCommand.steps.ts View File

@ -1131,7 +1131,7 @@ export async function* pickRepositoryStep<
state.repo = Container.instance.git.getRepository(state.repo); state.repo = Container.instance.git.getRepository(state.repo);
if (state.repo != null) return 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<RepositoryQuickPickItem>({ const step = QuickCommand.createPickStep<RepositoryQuickPickItem>({
title: context.title, title: context.title,
@ -1194,7 +1194,7 @@ export async function* pickRepositoriesStep<
actives = state.repos; actives = state.repos;
} }
} else { } else {
const active = await Container.instance.git.getOrCreateRepositoryForEditor();
const active = await Container.instance.git.getOrOpenRepositoryForEditor();
actives = active != null ? [active] : []; actives = active != null ? [active] : [];
} }

+ 2
- 2
src/commands/stashSave.ts View File

@ -42,7 +42,7 @@ export class StashSaveCommand extends Command {
} else if (context.type === 'scm-states') { } else if (context.type === 'scm-states') {
args = { ...args }; args = { ...args };
args.uris = context.scmResourceStates.map(s => s.resourceUri); 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); const status = await this.container.git.getStatusForRepo(args.repoPath);
if (status?.computeWorkingTreeStatus().staged) { if (status?.computeWorkingTreeStatus().staged) {
@ -60,7 +60,7 @@ export class StashSaveCommand extends Command {
(a, b) => a.concat(b.resourceStates.map(s => s.resourceUri)), (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); const status = await this.container.git.getStatusForRepo(args.repoPath);
if (status?.computeWorkingTreeStatus().staged) { if (status?.computeWorkingTreeStatus().staged) {

+ 6
- 6
src/env/node/git/localGitProvider.ts View File

@ -338,7 +338,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
} }
} }
createRepository(
openRepository(
folder: WorkspaceFolder, folder: WorkspaceFolder,
uri: Uri, uri: Uri,
root: boolean, root: boolean,
@ -358,7 +358,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
); );
} }
createRepositoryInitWatcher(): RepositoryInitWatcher {
openRepositoryInitWatcher(): RepositoryInitWatcher {
const watcher = workspace.createFileSystemWatcher('**/.git', false, true, true); const watcher = workspace.createFileSystemWatcher('**/.git', false, true, true);
return { return {
onDidCreate: watcher.onDidCreate, onDidCreate: watcher.onDidCreate,
@ -386,7 +386,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
const uri = await this.findRepositoryUri(folder.uri, true); const uri = await this.findRepositoryUri(folder.uri, true);
if (uri != null) { if (uri != null) {
Logger.log(cc, `found root repository in '${uri.fsPath}'`); 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; if (depth <= 0) return repositories;
@ -443,7 +443,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
if (rp == null) continue; if (rp == null) continue;
Logger.log(cc, `found repository in '${rp.fsPath}'`); Logger.log(cc, `found repository in '${rp.fsPath}'`);
repositories.push(this.createRepository(folder, rp, false));
repositories.push(this.openRepository(folder, rp, false));
} }
return repositories; 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) // 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)); tracked = Boolean(await Git.ls_files(newRepoPath, newRelativePath));
if (tracked) { 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) { if (repository != null) {
return splitPath(path, repository.path); return splitPath(path, repository.path);
} }
@ -3388,7 +3388,7 @@ export class LocalGitProvider implements GitProvider, Disposable {
const index = relativePath.indexOf('/'); const index = relativePath.indexOf('/');
if (index < 0 || index === relativePath.length - 1) return undefined; 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) { if (nested != null && nested !== repository) {
[relativePath, repoPath] = splitPath(path, repository.path); [relativePath, repoPath] = splitPath(path, repository.path);
repository = undefined; repository = undefined;

+ 2
- 8
src/git/gitProvider.ts View File

@ -82,14 +82,8 @@ export interface GitProvider extends Disposable {
discoverRepositories(uri: Uri): Promise<Repository[]>; discoverRepositories(uri: Uri): Promise<Repository[]>;
updateContext?(): void; 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<ScmRepository[]>; getOpenScmRepositories(): Promise<ScmRepository[]>;
getOrOpenScmRepository(repoPath: string): Promise<ScmRepository | undefined>; getOrOpenScmRepository(repoPath: string): Promise<ScmRepository | undefined>;

+ 8
- 8
src/git/gitProviderService.ts View File

@ -294,7 +294,7 @@ export class GitProviderService implements Disposable {
const disposables = []; const disposables = [];
const watcher = provider.createRepositoryInitWatcher?.();
const watcher = provider.openRepositoryInitWatcher?.();
if (watcher != null) { if (watcher != null) {
disposables.push( disposables.push(
watcher, watcher,
@ -331,7 +331,7 @@ export class GitProviderService implements Disposable {
if (repository != null) { if (repository != null) {
repository.closed = false; repository.closed = false;
} else { } else {
void this.getOrCreateRepository(e.uri);
void this.getOrOpenRepository(e.uri);
} }
}), }),
); );
@ -1424,8 +1424,8 @@ export class GitProviderService implements Disposable {
private _pendingRepositories = new Map<string, Promise<Repository | undefined>>(); private _pendingRepositories = new Map<string, Promise<Repository | undefined>>();
@log<GitProviderService['getRepository']>({ exit: r => `returned ${r?.path}` })
async getOrCreateRepository(uri: Uri, detectNested?: boolean): Promise<Repository | undefined> {
@log<GitProviderService['getOrOpenRepository']>({ exit: r => `returned ${r?.path}` })
async getOrOpenRepository(uri: Uri, detectNested?: boolean): Promise<Repository | undefined> {
const cc = Logger.getCorrelationContext(); const cc = Logger.getCorrelationContext();
const folderPath = dirname(uri.fsPath); const folderPath = dirname(uri.fsPath);
@ -1480,7 +1480,7 @@ export class GitProviderService implements Disposable {
} }
Logger.log(cc, `Repository found in '${repoUri.toString(false)}'`); 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._repositories.add(repository);
this._pendingRepositories.delete(key); this._pendingRepositories.delete(key);
@ -1499,15 +1499,15 @@ export class GitProviderService implements Disposable {
return promise; return promise;
} }
@log<GitProviderService['getOrCreateRepositoryForEditor']>({
@log<GitProviderService['getOrOpenRepositoryForEditor']>({
args: { 0: e => (e != null ? `TextEditor(${Logger.toLoggable(e.document.uri)})` : undefined) }, args: { 0: e => (e != null ? `TextEditor(${Logger.toLoggable(e.document.uri)})` : undefined) },
}) })
async getOrCreateRepositoryForEditor(editor?: TextEditor): Promise<Repository | undefined> {
async getOrOpenRepositoryForEditor(editor?: TextEditor): Promise<Repository | undefined> {
editor = editor ?? window.activeTextEditor; editor = editor ?? window.activeTextEditor;
if (editor == null) return this.highlander; if (editor == null) return this.highlander;
return this.getOrCreateRepository(editor.document.uri);
return this.getOrOpenRepository(editor.document.uri);
} }
getRepository(uri: Uri): Repository | undefined; getRepository(uri: Uri): Repository | undefined;

+ 4
- 4
src/git/gitUri.ts View File

@ -262,7 +262,7 @@ export class GitUri extends (Uri as any as UriEx) {
} catch {} } catch {}
if (data?.path) { 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) { if (repository == null) {
debugger; debugger;
throw new Error(`Unable to find repository for uri=${uri.toString(false)}`); 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 {} } catch {}
if (data?.fileName) { 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) { if (repository == null) {
debugger; debugger;
throw new Error(`Unable to find repository for uri=${uri.toString(false)}`); 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); repoPath = repoPath.substr(0, repoPath.length - data.fileName.length - 1);
} else { } else {
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain // 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) { if (!repoPath) {
debugger; 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); return new GitUri(uri, repository?.path);
} }

Loading…
Cancel
Save