{"record":{"id":"5da981b606bbfa33","repo":"zed-industries/zed","slug":"git-merge-base-is-ancestor-failed","errorCode":null,"errorMessage":"git merge-base --is-ancestor failed","messagePattern":"git merge-base --is-ancestor failed","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"crates/eval_cli/zed_eval/source.py","lineNumber":119,"sourceCode":"    if not (commit_present(base_sha) and commit_present(main_sha)):\n        subprocess.run(\n            [\"git\", \"-C\", repo_root(), \"fetch\", \"--quiet\", repo_url, \"main\"],\n            capture_output=True,\n        )\n    if not commit_present(main_sha):\n        raise RuntimeError(\n            f\"origin/main tip {main_sha[:12]} unavailable locally after fetch\"\n        )\n    if not commit_present(base_sha):\n        # Not present even after pulling main's history -> not reachable from main.\n        return False\n    ancestry = subprocess.run(\n        [\"git\", \"-C\", repo_root(), \"merge-base\", \"--is-ancestor\", base_sha, main_sha],\n        capture_output=True,\n    )\n    if ancestry.returncode in (0, 1):\n        return ancestry.returncode == 0\n    raise RuntimeError(\n        (ancestry.stderr or b\"\").decode(errors=\"replace\").strip()\n        or \"git merge-base --is-ancestor failed\"\n    )\n\n\ndef resolve_git_ref(ref: str) -> str:\n    return git_output([\"rev-parse\", \"--verify\", f\"{ref}^{{commit}}\"])\n\n\n_FULL_SHA_RE = re.compile(r\"[0-9a-fA-F]{40}\")\n\n\ndef resolve_remote_ref(repo_url: str, ref: str) -> str:\n    \"\"\"Resolve a git ref/tag/branch/SHA to a canonical commit SHA against the\n    *remote* repo, so the resulting build id is identical for every launcher\n    regardless of what they happen to have fetched locally.\n\n    A full 40-char SHA is already canonical and is returned (lowercased) without","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/zed-industries/zed/blob/f4178619acd0d47ea1f76a2025c42962c6d6638c/crates/eval_cli/zed_eval/source.py#L101-L137","documentation":"Once both shas are present locally, the code asks git whether base_sha is an ancestor of main_sha via `git merge-base --is-ancestor`. Git exits 0 for yes and 1 for no; any other exit code means git itself failed (missing object, corrupt repository, usage error), so this RuntimeError is raised with git's decoded stderr when available, otherwise the generic message.","triggerScenarios":"A corrupted object database after an interrupted fetch; a partial clone where an object referenced by one sha is missing despite ref presence; a damaged .git after disk-full; exotic git versions or wrappers returning unexpected codes.","commonSituations":"CI caching a broken .git directory between jobs; blob-filtered partial clones on constrained runners; disk-full during earlier git operations.","solutions":["Reproduce by hand: git -C <repo> merge-base --is-ancestor <base_sha> <main_sha>; echo $?","Run git fsck to detect corruption, then re-fetch or re-clone if it reports errors","Free disk space — full disks corrupt object writes","Update git if the installed version is ancient or a wrapper interferes"],"exampleFix":"# before\n# RuntimeError: git merge-base --is-ancestor failed\n\n# after\ngit -C $REPO fsck --full        # find corruption\ngit -C $REPO fetch --all --prune # repair refs/objects, then retry","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    on_main = check_ancestry(base_sha, main_sha)\nexcept RuntimeError as err:\n    if \"merge-base\" in str(err):\n        repair_repo(repo_root())  # git fsck + re-fetch, then retry once\n        on_main = check_ancestry(base_sha, main_sha)\n    else:\n        raise","preventionTips":["Avoid caching .git directories between CI jobs without validation","Run git fsck periodically on long-lived eval repos","Treat merge-base exit codes >1 as infrastructure failure, never as a verdict on ancestry"],"tags":["git","merge-base","corruption","subprocess"],"backgroundTag":"git-command-failed","analyzedSha":"f4178619acd0d47ea1f76a2025c42962c6d6638c","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}