(params: WorkspaceForkParams)
| 1010 | } |
| 1011 | |
| 1012 | async forkWorkspace(params: WorkspaceForkParams): Promise<WorkspaceForkResult> { |
| 1013 | const { projectPath, sourceWorkspaceName, newWorkspaceName, initLogger, abortSignal } = params; |
| 1014 | const throwIfAborted = () => { |
| 1015 | if (abortSignal?.aborted) { |
| 1016 | throw new Error("Docker workspace fork aborted"); |
| 1017 | } |
| 1018 | }; |
| 1019 | |
| 1020 | const srcContainerName = getContainerName(projectPath, sourceWorkspaceName); |
| 1021 | const destContainerName = getContainerName(projectPath, newWorkspaceName); |
| 1022 | const hostTempPath = path.join(os.tmpdir(), `mux-fork-${Date.now()}.bundle`); |
| 1023 | const containerBundlePath = "/tmp/fork.bundle"; |
| 1024 | let destContainerCreated = false; |
| 1025 | let forkSucceeded = false; |
| 1026 | |
| 1027 | try { |
| 1028 | throwIfAborted(); |
| 1029 | |
| 1030 | // 1. Verify source container exists |
| 1031 | const srcCheck = await runDockerCommand( |
| 1032 | `docker inspect ${srcContainerName}`, |
| 1033 | 10000, |
| 1034 | abortSignal |
| 1035 | ); |
| 1036 | if (srcCheck.exitCode !== 0) { |
| 1037 | return { |
| 1038 | success: false, |
| 1039 | error: `Source workspace container not found: ${srcContainerName}`, |
| 1040 | }; |
| 1041 | } |
| 1042 | |
| 1043 | // 2. Get current branch from source |
| 1044 | initLogger.logStep("Detecting source workspace branch..."); |
| 1045 | throwIfAborted(); |
| 1046 | const branchResult = await runDockerCommand( |
| 1047 | `docker exec ${srcContainerName} git -C ${CONTAINER_SRC_DIR} branch --show-current`, |
| 1048 | 30000, |
| 1049 | abortSignal |
| 1050 | ); |
| 1051 | const sourceBranch = branchResult.stdout.trim(); |
| 1052 | if (branchResult.exitCode !== 0 || sourceBranch.length === 0) { |
| 1053 | return { |
| 1054 | success: false, |
| 1055 | error: "Failed to detect branch in source workspace (detached HEAD?)", |
| 1056 | }; |
| 1057 | } |
| 1058 | |
| 1059 | // 3. Create git bundle inside source container |
| 1060 | initLogger.logStep("Creating git bundle from source..."); |
| 1061 | throwIfAborted(); |
| 1062 | const bundleResult = await runDockerCommand( |
| 1063 | `docker exec ${srcContainerName} git -C ${CONTAINER_SRC_DIR} bundle create ${containerBundlePath} --all`, |
| 1064 | 300000, |
| 1065 | abortSignal |
| 1066 | ); |
| 1067 | if (bundleResult.exitCode !== 0) { |
| 1068 | return { success: false, error: `Failed to create git bundle: ${bundleResult.stderr}` }; |
| 1069 | } |
nothing calls this directly
no test coverage detected