fix(ui): route answer worktrees from source session

This commit is contained in:
Bohdan Triapitsyn
2026-09-04 19:46:21 +03:00
parent f160f3aac4
commit b4a38061bc
7 changed files with 234 additions and 61 deletions
@@ -1,8 +1,15 @@
import { getGitBranches, getGitStatus } from '@/lib/gitApi';
import { checkIsGitRepository, getGitBranches, getGitStatus } from '@/lib/gitApi';
import type { CreateWorktreeArgs, ProjectRef } from '@/lib/worktrees/worktreeManager';
import { createWorktree } from '@/lib/worktrees/worktreeManager';
import { getRootBranch, resolveProjectRoot } from '@/lib/worktrees/worktreeStatus';
export class WorktreeRequiresGitRepositoryError extends Error {
constructor() {
super('Worktree creation requires a Git repository');
this.name = 'WorktreeRequiresGitRepositoryError';
}
}
const parseTrackingRef = (tracking: string | null | undefined): { remote: string; branch: string } | null => {
const value = String(tracking || '').trim().replace(/^remotes\//, '');
if (!value) {
@@ -162,6 +169,10 @@ export const createWorktreeWithDefaults = async (
args: CreateWorktreeArgs,
options?: { resolvedRootTrackingRemote?: string | null }
) => {
const isGitRepository = await checkIsGitRepository(project.path);
if (!isGitRepository) {
throw new WorktreeRequiresGitRepositoryError();
}
const remoteArgs = await withWorktreeRemoteStartRef(project, args);
const resolvedArgs = await withWorktreeUpstreamDefaults(project.path, remoteArgs, options);
return createWorktree(project, resolvedArgs);