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