{"record":{"id":"2ef8bb833029f24a","repo":"badges/shields","slug":"no-common-ancestor","errorCode":null,"errorMessage":"no common ancestor","messagePattern":"no common ancestor","errorType":"validation","errorClass":"InvalidParameter","httpStatus":400,"severity":"error","filePath":"services/github/github-commit-status.service.js","lineNumber":74,"sourceCode":"        message: `not in ${branch}`,\n        color: 'yellow',\n      }\n    }\n  }\n\n  async handle({ user, repo, branch, commit }) {\n    let status\n    try {\n      ;({ status } = await this._requestJson({\n        url: `/repos/${user}/${repo}/compare/${branch}...${commit}`,\n        httpErrors: httpErrorsFor('commit or branch not found'),\n        schema,\n      }))\n    } catch (e) {\n      if (e instanceof NotFound) {\n        const { message } = this._parseJson(e.buffer)\n        if (message && message.startsWith('No common ancestor between')) {\n          throw new InvalidParameter({ prettyMessage: 'no common ancestor' })\n        }\n      }\n      throw e\n    }\n\n    const isInBranch = status === 'identical' || status === 'behind'\n    return this.constructor.render({ isInBranch, branch })\n  }\n}\n","sourceCodeStart":56,"sourceCodeEnd":84,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/github/github-commit-status.service.js#L56-L84","documentation":"The commit-status service compares commits between branches; when GitHub's API responds with NotFound whose JSON message starts with 'No common ancestor between', handle() rethrows it as InvalidParameter with 'no common ancestor'. GitHub cannot compute a comparison (ahead/behind/identical) for refs that share no merge-base. This is an input problem: the two requested refs are unrelated histories.","triggerScenarios":"Requesting github/commit-status for a base branch and head ref whose histories are disjoint, e.g. comparing an orphan branch (gh-pages created with --orphan, or a brand-new unrelated repo) against main, so GitHub replies 'No common ancestor between ...'.","commonSituations":"Comparing feature branches to an orphaned gh-pages branch; forks with rewritten history; comparing across repos with unrelated roots; a branch recreated from scratch with no shared commit history.","solutions":["Check the two refs actually share history: `git merge-base <ref1> <ref2>` locally; if it fails, the comparison is meaningless.","Choose a base branch that is an ancestor of the head branch instead of an orphan branch.","If gh-pages is orphaned, rebase/recreate it from the default branch or compare against the intended source branch."],"exampleFix":"// before\n/service/github/commit-status/user/repo/main/gh-pages.json\n// after (compare against a related branch)\n/service/github/commit-status/user/repo/main/feature-branch.json","handlingStrategy":"validation","validationCode":"// ensure refs share history before comparing\nimport { execSync } from 'child_process';\ntry { execSync(`git merge-base origin/${base} ${head}`, { stdio: 'pipe' }); } catch { throw new Error('refs have no common ancestor'); }","typeGuard":"function isComparableRefs(refA, refB) {\n  return typeof refA === 'string' && typeof refB === 'string' && refA !== refB && !refB.startsWith('gh-pages');\n}","tryCatchPattern":"try {\n  const status = await getCommitStatus({ base, head });\n} catch (e) {\n  if (e.prettyMessage === 'no common ancestor') {\n    return { status: 'unrelated' }; // or prompt user to pick a related base\n  } else throw e;\n}","preventionTips":["Avoid comparing against orphan branches (gh-pages created with --orphan).","Run `git merge-base` locally when setting up comparison badges.","Keep feature branches created from the branch you compare against."],"tags":["github","invalid-parameter","git-history","merge-base"],"backgroundTag":"no-common-ancestor","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}