{"record":{"id":"593317fa4ae64c44","repo":"usestrix/strix","slug":"unable-to-compute-merge-base-against-base-ref-593317","errorCode":null,"errorMessage":"Unable to compute merge-base against '{base_ref}' for '{source_path}'. Ensure the base branch history is fetched and reachable.","messagePattern":"Unable to compute merge-base against '(.+?)' for '(.+?)'\\. Ensure the base branch history is fetched and reachable\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"strix/interface/utils.py","lineNumber":977,"sourceCode":"\n    if _is_repo_shallow(repo_path):\n        raise ValueError(\n            \"Strix requires full git history for diff-scope. Please set fetch-depth: 0 \"\n            \"in your CI config.\"\n        )\n\n    base_ref = _resolve_base_ref(repo_path, diff_base, env)\n    merge_base_result = _run_git_command(repo_path, [\"merge-base\", base_ref, \"HEAD\"], check=False)\n    if merge_base_result.returncode != 0:\n        stderr = merge_base_result.stderr.strip()\n        raise ValueError(\n            f\"Unable to compute merge-base against '{base_ref}' for '{source_path}'. \"\n            f\"{stderr or 'Ensure the base branch history is fetched and reachable.'}\"\n        )\n\n    merge_base = merge_base_result.stdout.strip()\n    if not merge_base:\n        raise ValueError(\n            f\"Unable to compute merge-base against '{base_ref}' for '{source_path}'. \"\n            \"Ensure the base branch history is fetched and reachable.\"\n        )\n\n    diff_result = _run_git_command_raw(\n        repo_path,\n        [\n            \"diff\",\n            \"--name-status\",\n            \"-z\",\n            \"--find-renames\",\n            \"--find-copies\",\n            f\"{merge_base}...HEAD\",\n        ],\n        check=False,\n    )\n    if diff_result.returncode != 0:\n        stderr = diff_result.stderr.decode(\"utf-8\", errors=\"replace\").strip()","sourceCodeStart":959,"sourceCodeEnd":995,"githubUrl":"https://github.com/usestrix/strix/blob/85513391305171ecc6faffe03da4a8bda5e3febb/strix/interface/utils.py#L959-L995","documentation":"Raised by _resolve_repo_diff_scope (utils.py:977) as the fallback when `git merge-base <base_ref> HEAD` exits zero but prints an empty sha. Git can succeed without producing a usable ancestor in edge cases (e.g. unborn HEAD, pathological ref setups), and Strix treats an empty merge-base the same as a failed one. The message omits stderr because there is none, and instead advises ensuring base history is fetched and reachable.","triggerScenarios":"HEAD points at an unborn branch (fresh repo with no commits, or a checkout of an empty branch); the merge-base command emitting only whitespace due to ref aliasing oddities; rare graft/replace configurations where the computed base resolves empty.","commonSituations":"Running diff-scope on a brand-new repo with no initial commit; CI checking out an empty branch; repos mid-rebase with detached/empty HEAD; corrupted refs returning empty revs.","solutions":["Ensure HEAD has at least one commit (git log HEAD -1) before using diff-scope","git fetch --unshallow / fetch the base branch so the ancestor is real and reachable","Inspect refs: git show-ref and git rev-parse <base_ref> HEAD to spot empty/unborn refs","Skip diff-scope for empty or brand-new repositories and scan the whole tree"],"exampleFix":"# before\n# repo with zero commits on current branch\nstrix -t . --diff-scope  # empty merge-base ValueError\n\n# after\ngit commit --allow-empty -m \"initial\"\ngit fetch origin main\nstrix -t . --diff-scope --diff-base origin/main","handlingStrategy":"validation","validationCode":"r = subprocess.run([\"git\", \"-C\", repo, \"merge-base\", base_ref, \"HEAD\"], capture_output=True, text=True)\nif r.returncode == 0 and not r.stdout.strip():\n    raise SystemExit(\"empty merge-base; ensure HEAD has commits and base history is fetched\")","typeGuard":"def merge_base_usable(repo: str, base_ref: str) -> bool:\n    import subprocess\n    r = subprocess.run([\"git\", \"-C\", repo, \"merge-base\", base_ref, \"HEAD\"], capture_output=True, text=True)\n    return r.returncode == 0 and bool(r.stdout.strip())","tryCatchPattern":"try:\n    run_diff_scope_scan()\nexcept ValueError as e:\n    if \"merge-base\" in str(e) and \"fetched and reachable\" in str(e):\n        ensure_head_has_commits(); git_fetch_base(); retry_once()\n    else:\n        raise","preventionTips":["Never run diff-scope on unborn branches or empty repos","Confirm git log HEAD -1 succeeds before the scan","Fetch base history so the ancestor is genuinely reachable"],"tags":["git","diff-scope","merge-base","edge-case"],"backgroundTag":null,"analyzedSha":"85513391305171ecc6faffe03da4a8bda5e3febb","analyzedAt":"2026-08-15T05:03:57.275Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}