Browse Source

Adds more logging and trap for Fixes #2530

main
Eric Amodio 1 year ago
parent
commit
4891099303
2 changed files with 13 additions and 1 deletions
  1. +11
    -1
      src/commands/git/worktree.ts
  2. +2
    -0
      src/git/models/repository.ts

+ 11
- 1
src/commands/git/worktree.ts View File

@ -101,6 +101,15 @@ type CreateStepState = WorktreeStepState
type DeleteStepState<T extends DeleteState = DeleteState> = WorktreeStepState<ExcludeSome<T, 'repo', string>>;
type OpenStepState<T extends OpenState = OpenState> = WorktreeStepState<ExcludeSome<T, 'repo', string>>;
function assertStateStepRepository(
state: PartialStepState<State>,
): asserts state is PartialStepState<State> & { repo: Repository } {
if (state.repo != null && typeof state.repo !== 'string') return;
debugger;
throw new Error('Missing repository');
}
const subcommandToTitleMap = new Map<State['subcommand'], string>([
['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);

+ 2
- 0
src/git/models/repository.ts View File

@ -646,6 +646,7 @@ export class Repository implements Disposable {
}
@gate()
@log<Repository['getMainRepository']>({ exit: r => `returned ${r?.path}` })
async getMainRepository(): Promise<Repository | undefined> {
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 },

Loading…
Cancel
Save