* Fetch trunk branch from origin into its remote-tracking ref before checkout. * Returns true if fetch succeeded (origin is available for branching).
(
workspacePath: string,
trunkBranch: string,
initLogger: InitLogger,
abortSignal?: AbortSignal,
nhp = ""
)
| 2972 | * Returns true if fetch succeeded (origin is available for branching). |
| 2973 | */ |
| 2974 | private async fetchOriginTrunk( |
| 2975 | workspacePath: string, |
| 2976 | trunkBranch: string, |
| 2977 | initLogger: InitLogger, |
| 2978 | abortSignal?: AbortSignal, |
| 2979 | nhp = "" |
| 2980 | ): Promise<boolean> { |
| 2981 | try { |
| 2982 | initLogger.logStep(`Fetching latest from origin/${trunkBranch}...`); |
| 2983 | |
| 2984 | const remoteTrackingRefSpec = `+refs/heads/${trunkBranch}:refs/remotes/origin/${trunkBranch}`; |
| 2985 | const fetchCmd = `${nhp}git fetch origin ${shescape.quote(remoteTrackingRefSpec)}`; |
| 2986 | const fetchStream = await this.exec(fetchCmd, { |
| 2987 | cwd: workspacePath, |
| 2988 | timeout: 120, // 2 minutes for network operation |
| 2989 | abortSignal, |
| 2990 | }); |
| 2991 | |
| 2992 | const fetchExitCode = await fetchStream.exitCode; |
| 2993 | if (fetchExitCode !== 0) { |
| 2994 | const fetchStderr = await streamToString(fetchStream.stderr); |
| 2995 | // Branch doesn't exist on origin (common for subagent local-only branches) |
| 2996 | if (fetchStderr.includes("couldn't find remote ref")) { |
| 2997 | initLogger.logStep(`Branch "${trunkBranch}" not found on origin; using local state.`); |
| 2998 | } else { |
| 2999 | initLogger.logStderr( |
| 3000 | `Note: Could not fetch from origin (${fetchStderr}), using local branch state` |
| 3001 | ); |
| 3002 | } |
| 3003 | return false; |
| 3004 | } |
| 3005 | |
| 3006 | initLogger.logStep("Fetched latest from origin"); |
| 3007 | return true; |
| 3008 | } catch (error) { |
| 3009 | const errorMsg = getErrorMessage(error); |
| 3010 | initLogger.logStderr( |
| 3011 | `Note: Could not fetch from origin (${errorMsg}), using local branch state` |
| 3012 | ); |
| 3013 | return false; |
| 3014 | } |
| 3015 | } |
| 3016 | |
| 3017 | /** |
| 3018 | * Check if the local <branch> can fast-forward to origin/<branch>. |
no test coverage detected