usestrix/strix · error · ValueError

Unable to compute merge-base against '{base_ref}' for '{sour

Error message

Unable to compute merge-base against '{base_ref}' for '{source_path}'. Ensure the base branch history is fetched and reachable.

What it means

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.

Source

Thrown at strix/interface/utils.py:977

    if _is_repo_shallow(repo_path):
        raise ValueError(
            "Strix requires full git history for diff-scope. Please set fetch-depth: 0 "
            "in your CI config."
        )

    base_ref = _resolve_base_ref(repo_path, diff_base, env)
    merge_base_result = _run_git_command(repo_path, ["merge-base", base_ref, "HEAD"], check=False)
    if merge_base_result.returncode != 0:
        stderr = merge_base_result.stderr.strip()
        raise ValueError(
            f"Unable to compute merge-base against '{base_ref}' for '{source_path}'. "
            f"{stderr or 'Ensure the base branch history is fetched and reachable.'}"
        )

    merge_base = merge_base_result.stdout.strip()
    if not merge_base:
        raise ValueError(
            f"Unable to compute merge-base against '{base_ref}' for '{source_path}'. "
            "Ensure the base branch history is fetched and reachable."
        )

    diff_result = _run_git_command_raw(
        repo_path,
        [
            "diff",
            "--name-status",
            "-z",
            "--find-renames",
            "--find-copies",
            f"{merge_base}...HEAD",
        ],
        check=False,
    )
    if diff_result.returncode != 0:
        stderr = diff_result.stderr.decode("utf-8", errors="replace").strip()

View on GitHub (pinned to 8551339130)

Solutions

  1. Ensure HEAD has at least one commit (git log HEAD -1) before using diff-scope
  2. git fetch --unshallow / fetch the base branch so the ancestor is real and reachable
  3. Inspect refs: git show-ref and git rev-parse <base_ref> HEAD to spot empty/unborn refs
  4. Skip diff-scope for empty or brand-new repositories and scan the whole tree

Example fix

# before
# repo with zero commits on current branch
strix -t . --diff-scope  # empty merge-base ValueError

# after
git commit --allow-empty -m "initial"
git fetch origin main
strix -t . --diff-scope --diff-base origin/main
Defensive patterns

Strategy: validation

Validate before calling

r = subprocess.run(["git", "-C", repo, "merge-base", base_ref, "HEAD"], capture_output=True, text=True)
if r.returncode == 0 and not r.stdout.strip():
    raise SystemExit("empty merge-base; ensure HEAD has commits and base history is fetched")

Type guard

def merge_base_usable(repo: str, base_ref: str) -> bool:
    import subprocess
    r = subprocess.run(["git", "-C", repo, "merge-base", base_ref, "HEAD"], capture_output=True, text=True)
    return r.returncode == 0 and bool(r.stdout.strip())

Try / catch

try:
    run_diff_scope_scan()
except ValueError as e:
    if "merge-base" in str(e) and "fetched and reachable" in str(e):
        ensure_head_has_commits(); git_fetch_base(); retry_once()
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of usestrix/strix@8551339130 (2026-08-15). Data as JSON: /api/errors/593317fa4ae64c44. Report an issue: GitHub.