(
params: WorkspaceForkParams,
options?: {
/**
* Explicit source checkout path. Overrides the name-derived path for sources whose
* persisted path diverges from their name (e.g. isolation: "none" tasks sharing a parent
* checkout). See WorktreeRuntime.forkWorkspace.
*/
sourceWorkspacePath?: string;
}
)
| 886 | } |
| 887 | |
| 888 | async forkWorkspace( |
| 889 | params: WorkspaceForkParams, |
| 890 | options?: { |
| 891 | /** |
| 892 | * Explicit source checkout path. Overrides the name-derived path for sources whose |
| 893 | * persisted path diverges from their name (e.g. isolation: "none" tasks sharing a parent |
| 894 | * checkout). See WorktreeRuntime.forkWorkspace. |
| 895 | */ |
| 896 | sourceWorkspacePath?: string; |
| 897 | } |
| 898 | ): Promise<WorkspaceForkResult> { |
| 899 | const { projectPath, sourceWorkspaceName, newWorkspaceName, initLogger } = params; |
| 900 | |
| 901 | // Get source workspace path |
| 902 | const sourceWorkspacePath = |
| 903 | options?.sourceWorkspacePath ?? this.getWorkspacePath(projectPath, sourceWorkspaceName); |
| 904 | |
| 905 | // Get current branch from source workspace |
| 906 | try { |
| 907 | using proc = execFileAsync( |
| 908 | "git", |
| 909 | ["-C", sourceWorkspacePath, "branch", "--show-current"], |
| 910 | params.abortSignal ? { signal: params.abortSignal } : undefined |
| 911 | ); |
| 912 | const { stdout } = await proc.result; |
| 913 | const sourceBranch = stdout.trim(); |
| 914 | |
| 915 | if (!sourceBranch) { |
| 916 | return { |
| 917 | success: false, |
| 918 | error: "Failed to detect branch in source workspace", |
| 919 | }; |
| 920 | } |
| 921 | |
| 922 | // Use createWorkspace with sourceBranch as trunk to fork from source branch |
| 923 | const createResult = await this.createWorkspace({ |
| 924 | projectPath, |
| 925 | branchName: newWorkspaceName, |
| 926 | directoryName: newWorkspaceName, |
| 927 | trunkBranch: sourceBranch, // Fork from source branch instead of main/master |
| 928 | initLogger, |
| 929 | abortSignal: params.abortSignal, |
| 930 | env: params.env, |
| 931 | trusted: params.trusted, |
| 932 | }); |
| 933 | |
| 934 | if (!createResult.success || !createResult.workspacePath) { |
| 935 | return { |
| 936 | success: false, |
| 937 | error: createResult.error ?? "Failed to create workspace", |
| 938 | }; |
| 939 | } |
| 940 | |
| 941 | return { |
| 942 | success: true, |
| 943 | workspacePath: createResult.workspacePath, |
| 944 | sourceBranch, |
| 945 | }; |
nothing calls this directly
no test coverage detected