* 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
)
| 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. |
no test coverage detected