{"record":{"id":"04b822c0839f06ca","repo":"koala73/worldmonitor","slug":"cannot-resolve-origin-main-for-the-deploy-drift-comparison","errorCode":null,"errorMessage":"cannot resolve origin/main for the deploy-drift comparison; fetch main or pass --head explicitly","messagePattern":"cannot resolve origin/main for the deploy-drift comparison; fetch main or pass --head explicitly","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/check-railway-deploy-drift.mjs","lineNumber":775,"sourceCode":"  if (explicit === null || refreshMain) {\n    git([\n      'fetch',\n      '--quiet',\n      'origin',\n      '+refs/heads/main:refs/remotes/origin/main',\n    ]);\n  }\n  let originMainSha = null;\n  try {\n    originMainSha = git(['rev-parse', '--verify', '--end-of-options', 'origin/main^{commit}']);\n  } catch (error) {\n    // Symmetric with the fetch condition above. A refresh call always passes an\n    // explicit --head, so keying this on `explicit === null` alone would swallow\n    // the failure and hand back originMainSha: null — which reads downstream as\n    // \"no commit is on authorized main\" and blocks the whole fleet with a detail\n    // string blaming the deployment source rather than this resolution failure.\n    if (explicit === null || refreshMain) {\n      throw new Error(\n        'cannot resolve origin/main for the deploy-drift comparison; fetch main or pass --head explicitly',\n        { cause: error },\n      );\n    }\n  }\n\n  let headSha = originMainSha;\n  let headSource = 'origin/main';\n  if (explicit !== null) {\n    headSource = '--head';\n    try {\n      headSha = git(['rev-parse', '--verify', '--end-of-options', `${explicit}^{commit}`]);\n    } catch (error) {\n      throw new Error(`cannot resolve --head ${explicit} to a commit`, { cause: error });\n    }\n  }\n\n  return {","sourceCodeStart":757,"sourceCodeEnd":793,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/scripts/check-railway-deploy-drift.mjs#L757-L793","documentation":"check-railway-deploy-drift compares deployed Railway commits against authorized main. resolveComparisonHead needs origin/main's SHA; when the git lookup of origin/main fails and no explicit --head was given (or a refresh of main was requested), it throws instead of returning originMainSha: null — because null would downstream read as 'no commits on authorized main' and falsely block the whole fleet with a message blaming the deployment source.","triggerScenarios":"Running the drift check (without --head, or with main refresh) in a shallow clone, fresh clone without `git fetch origin`, a repo whose remote branch is not named main, or offline / remote-fetch failure so origin/main ref cannot be resolved.","commonSituations":"CI checkout with depth=1 and no origin/main ref; developer forgot `git fetch origin` after cloning; remote renamed default branch to master/trunk; network/firewall blocking git fetch.","solutions":["Run `git fetch origin main` (or `git fetch --unshallow` in shallow clones) and re-run the check","Pass an explicit `--head <sha-or-ref>` so the comparison does not need to resolve origin/main","Verify the remote default branch name matches what the script expects (origin/main) and update remote/branch or script config accordingly","Check network/remote access if fetch itself is failing"],"exampleFix":"// before\nnode scripts/check-railway-deploy-drift.mjs\n// after\ngit fetch origin main && node scripts/check-railway-deploy-drift.mjs --head origin/main","handlingStrategy":"try-catch","validationCode":"try {\n  execSync('git rev-parse origin/main', { stdio: 'ignore' });\n} catch {\n  throw new Error('origin/main unresolvable — run git fetch origin main or pass --head');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runDriftCheck({ head });\n} catch (e) {\n  if (e.message.includes('cannot resolve origin/main')) {\n    execSync('git fetch origin main', { stdio: 'inherit' });\n    await runDriftCheck({ head: 'origin/main' });\n  } else throw e;\n}","preventionTips":["Run `git fetch origin main` before deploy-drift checks (or use --unshallow clones in CI)","Always pass an explicit --head in refresh/automation contexts","Confirm the remote default branch name matches origin/main","Keep network access to the git remote in CI jobs"],"tags":["git","cli","deploy","network"],"backgroundTag":"git-command-failed","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-15T18:17:12.389Z"}