From 4891099303e6d2aaa602b274c997371b7d776e53 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 1 Mar 2023 14:56:45 -0500 Subject: [PATCH] Adds more logging and trap for Fixes #2530 --- src/commands/git/worktree.ts | 12 +++++++++++- src/git/models/repository.ts | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/commands/git/worktree.ts b/src/commands/git/worktree.ts index 893662d..f4c7de9 100644 --- a/src/commands/git/worktree.ts +++ b/src/commands/git/worktree.ts @@ -101,6 +101,15 @@ type CreateStepState = WorktreeStepState = WorktreeStepState>; type OpenStepState = WorktreeStepState>; +function assertStateStepRepository( + state: PartialStepState, +): asserts state is PartialStepState & { repo: Repository } { + if (state.repo != null && typeof state.repo !== 'string') return; + + debugger; + throw new Error('Missing repository'); +} + const subcommandToTitleMap = new Map([ ['create', 'Create'], ['delete', 'Delete'], @@ -220,8 +229,9 @@ export class WorktreeGitCommand extends QuickCommand { // Ensure we use the "main" repository if we are in a worktree already state.repo = await state.repo.getMainRepository(); + assertStateStepRepository(state); - const result = yield* ensureAccessStep(state as any, context, PlusFeatures.Worktrees); + const result = yield* ensureAccessStep(state, context, PlusFeatures.Worktrees); if (result === StepResultBreak) break; context.title = getTitle(state.subcommand === 'delete' ? 'Worktrees' : this.title, state.subcommand); diff --git a/src/git/models/repository.ts b/src/git/models/repository.ts index f0df4cf..3a8620a 100644 --- a/src/git/models/repository.ts +++ b/src/git/models/repository.ts @@ -646,6 +646,7 @@ export class Repository implements Disposable { } @gate() + @log({ exit: r => `returned ${r?.path}` }) async getMainRepository(): Promise { const gitDir = await this.getGitDir(); if (gitDir?.commonUri == null) return this; @@ -719,6 +720,7 @@ export class Repository implements Disposable { return this.container.git.getTags(this.path, options); } + @log() async createWorktree( uri: Uri, options?: { commitish?: string; createBranch?: string; detach?: boolean; force?: boolean },