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

Method canFastForwardToOrigin

src/node/worktree/WorktreeManager.ts:306–332  ·  view source on GitHub ↗

* Check if local trunk can fast-forward to origin/ . * Returns true if local is behind or equal to origin (safe to use origin). * Returns false if local is ahead or diverged (preserve local state).

(
    projectPath: string,
    trunkBranch: string,
    initLogger: InitLogger,
    abortSignal?: AbortSignal
  )

Source from the content-addressed store, hash-verified

304 * Returns false if local is ahead or diverged (preserve local state).
305 */
306 private async canFastForwardToOrigin(
307 projectPath: string,
308 trunkBranch: string,
309 initLogger: InitLogger,
310 abortSignal?: AbortSignal
311 ): Promise<boolean> {
312 try {
313 // Check if local trunk is an ancestor of origin/trunk
314 // Exit code 0 = local is ancestor (can fast-forward), non-zero = cannot
315 using proc = execFileAsync(
316 "git",
317 ["-C", projectPath, "merge-base", "--is-ancestor", trunkBranch, `origin/${trunkBranch}`],
318 abortSignal ? { signal: abortSignal } : undefined
319 );
320 await proc.result;
321 return true; // Local is behind or equal to origin
322 } catch (error) {
323 if (isAbortError(error, abortSignal)) {
324 throw error;
325 }
326 // Local is ahead or diverged - preserve local state
327 initLogger.logStderr(
328 `Note: Local ${trunkBranch} is ahead of or diverged from origin, using local state`
329 );
330 return false;
331 }
332 }
333
334 /**
335 * Fast-forward merge to latest origin/<trunkBranch> after checkout.

Callers 1

createWorkspaceMethod · 0.95

Calls 3

execFileAsyncFunction · 0.90
logStderrMethod · 0.80
isAbortErrorFunction · 0.70

Tested by

no test coverage detected