MCPcopy
hub / github.com/coder/mux / fetchOriginTrunk

Method fetchOriginTrunk

src/node/worktree/WorktreeManager.ts:266–299  ·  view source on GitHub ↗

* Fetch trunk branch from origin before worktree creation. * Returns true if fetch succeeded (origin is available for branching).

(
    projectPath: string,
    trunkBranch: string,
    initLogger: InitLogger,
    noHooksEnv: GitExecOptions
  )

Source from the content-addressed store, hash-verified

264 * Returns true if fetch succeeded (origin is available for branching).
265 */
266 private async fetchOriginTrunk(
267 projectPath: string,
268 trunkBranch: string,
269 initLogger: InitLogger,
270 noHooksEnv: GitExecOptions
271 ): Promise<boolean> {
272 try {
273 initLogger.logStep(`Fetching latest from origin/${trunkBranch}...`);
274
275 using fetchProc = execFileAsync(
276 "git",
277 ["-C", projectPath, "fetch", "origin", trunkBranch],
278 noHooksEnv
279 );
280 await fetchProc.result;
281
282 initLogger.logStep("Fetched latest from origin");
283 return true;
284 } catch (error) {
285 if (isAbortError(error, noHooksEnv?.signal)) {
286 throw error;
287 }
288 const errorMsg = getErrorMessage(error);
289 // Branch doesn't exist on origin (common for subagent local-only branches)
290 if (errorMsg.includes("couldn't find remote ref")) {
291 initLogger.logStep(`Branch "${trunkBranch}" not found on origin; using local state.`);
292 } else {
293 initLogger.logStderr(
294 `Note: Could not fetch from origin (${errorMsg}), using local branch state`
295 );
296 }
297 return false;
298 }
299 }
300
301 /**
302 * Check if local trunk can fast-forward to origin/<trunk>.

Callers 1

createWorkspaceMethod · 0.95

Calls 5

execFileAsyncFunction · 0.90
getErrorMessageFunction · 0.90
logStepMethod · 0.80
logStderrMethod · 0.80
isAbortErrorFunction · 0.70

Tested by

no test coverage detected