MCPcopy Index your code
hub / github.com/coder/mux / prepareWorkspaceCheckout

Method prepareWorkspaceCheckout

src/node/runtime/SSHRuntime.ts:2755–2968  ·  view source on GitHub ↗
(params: WorkspaceInitParams, nhp: string)

Source from the content-addressed store, hash-verified

2753 }
2754
2755 private async prepareWorkspaceCheckout(params: WorkspaceInitParams, nhp: string): Promise<void> {
2756 const { projectPath, branchName, trunkBranch, workspacePath, initLogger, abortSignal, env } =
2757 params;
2758
2759 // STARTUP-PERF (warm fast-path): try to materialize the workspace in a
2760 // single fused SSH command. See `tryWarmWorktreeAdd()` for the contract
2761 // and miss reasons. When this succeeds, we skip the entire multi-call
2762 // slow path (test-d → git-check → ensureBaseRepo → snapshot check →
2763 // manifest check → refreshOrigin → fetchOrigin → resolveBundleTrunkRef →
2764 // resolveFreshWorkspaceSourceBase → worktree-add), collapsing ~9 sequential
2765 // SSH round-trips into one.
2766 const warmHit = await this.tryWarmWorktreeAdd(params, nhp);
2767 if (warmHit) {
2768 // STARTUP-PERF: The warm SSH command already reported whether
2769 // `.gitmodules` exists in the freshly-materialized worktree, so we can
2770 // skip the (otherwise unavoidable) probe-RTT inside
2771 // `hasRuntimeGitmodules()` when the answer is "missing". On a typical
2772 // single-package project this saves one full SSH round-trip on every
2773 // warm workspace create.
2774 if (warmHit.gitmodulesPresent) {
2775 await syncRuntimeGitSubmodules({
2776 runtime: this,
2777 workspacePath,
2778 initLogger,
2779 abortSignal,
2780 env,
2781 trusted: params.trusted,
2782 });
2783 }
2784 return;
2785 }
2786
2787 // If the workspace directory already exists and contains a git repo (e.g. forked from
2788 // another SSH workspace via worktree add or legacy cp), skip the expensive sync step.
2789 const workspacePathArg = expandTildeForSSH(workspacePath);
2790 let needsWorktreeCheckout = true;
2791 let workspacePathExistedBeforeCheckout = false;
2792
2793 try {
2794 const dirCheck = await execBuffered(this, `test -d ${workspacePathArg}`, {
2795 cwd: "/tmp",
2796 timeout: 10,
2797 abortSignal,
2798 });
2799 if (dirCheck.exitCode === 0) {
2800 workspacePathExistedBeforeCheckout = true;
2801 const gitCheck = await execBuffered(
2802 this,
2803 `git -C ${workspacePathArg} rev-parse --is-inside-work-tree`,
2804 {
2805 cwd: "/tmp",
2806 timeout: 20,
2807 abortSignal,
2808 }
2809 );
2810 needsWorktreeCheckout = gitCheck.exitCode !== 0;
2811 }
2812 } catch {

Callers 1

initWorkspaceMethod · 0.95

Tested by

no test coverage detected