* Fetches a specific branch from remote origin * @param branch The branch to fetch. If not specified, fetches all branches.
(branch?: string)
| 185 | * @param branch The branch to fetch. If not specified, fetches all branches. |
| 186 | */ |
| 187 | async function fetchFromOrigin(branch?: string): Promise<void> { |
| 188 | const fetchArgs = branch ? ['fetch', 'origin', `${branch}:${branch}`] : ['fetch', 'origin']; |
| 189 | const { |
| 190 | code: fetchCode, |
| 191 | stderr: fetchStderr |
| 192 | } = await execFileNoThrow(gitExe(), fetchArgs); |
| 193 | if (fetchCode !== 0) { |
| 194 | // If fetching a specific branch fails, it might not exist locally yet |
| 195 | // Try fetching just the ref without mapping to local branch |
| 196 | if (branch && fetchStderr.includes('refspec')) { |
| 197 | logForDebugging(`Specific branch fetch failed, trying to fetch ref: ${branch}`); |
| 198 | const { |
| 199 | code: refFetchCode, |
| 200 | stderr: refFetchStderr |
| 201 | } = await execFileNoThrow(gitExe(), ['fetch', 'origin', branch]); |
| 202 | if (refFetchCode !== 0) { |
| 203 | logError(new Error(`Failed to fetch from remote origin: ${refFetchStderr}`)); |
| 204 | } |
| 205 | } else { |
| 206 | logError(new Error(`Failed to fetch from remote origin: ${fetchStderr}`)); |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Ensures that the current branch has an upstream set |
no test coverage detected