fix(ui): route answer worktrees from source session
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user