koala73/worldmonitor · error · Error
cannot resolve origin/main for the deploy-drift comparison;
Error message
cannot resolve origin/main for the deploy-drift comparison; fetch main or pass --head explicitly
What it means
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.
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
Example fix
// before node scripts/check-railway-deploy-drift.mjs // after git fetch origin main && node scripts/check-railway-deploy-drift.mjs --head origin/main
Defensive patterns
Strategy: try-catch
Validate before calling
try {
execSync('git rev-parse origin/main', { stdio: 'ignore' });
} catch {
throw new Error('origin/main unresolvable — run git fetch origin main or pass --head');
} Try / catch
try {
await runDriftCheck({ head });
} catch (e) {
if (e.message.includes('cannot resolve origin/main')) {
execSync('git fetch origin main', { stdio: 'inherit' });
await runDriftCheck({ head: 'origin/main' });
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- git is required to prove the merge commit reached the defaul
- relay returned ${resp.status}
- global fetch is unavailable — Node 18+ is required
- DNS ${recordType} lookup failed: HTTP ${response.status}
- callbackUrl DNS resolution failed: ${message}
AI-assisted analysis of koala73/worldmonitor@7d06c8633d (2026-09-15).
Data as JSON: /api/errors/04b822c0839f06ca.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/check-railway-deploy-drift.mjs:775
if (explicit === null || refreshMain) {
git([
'fetch',
'--quiet',
'origin',
'+refs/heads/main:refs/remotes/origin/main',
]);
}
let originMainSha = null;
try {
originMainSha = git(['rev-parse', '--verify', '--end-of-options', 'origin/main^{commit}']);
} catch (error) {
// Symmetric with the fetch condition above. A refresh call always passes an
// explicit --head, so keying this on `explicit === null` alone would swallow
// the failure and hand back originMainSha: null — which reads downstream as
// "no commit is on authorized main" and blocks the whole fleet with a detail
// string blaming the deployment source rather than this resolution failure.
if (explicit === null || refreshMain) {
throw new Error(
'cannot resolve origin/main for the deploy-drift comparison; fetch main or pass --head explicitly',
{ cause: error },
);
}
}
let headSha = originMainSha;
let headSource = 'origin/main';
if (explicit !== null) {
headSource = '--head';
try {
headSha = git(['rev-parse', '--verify', '--end-of-options', `${explicit}^{commit}`]);
} catch (error) {
throw new Error(`cannot resolve --head ${explicit} to a commit`, { cause: error });
}
}
return {View on GitHub (pinned to 7d06c8633d)