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}'. {stderr or 'Ensure the base branch history is fetched and reachable.'}

What it means

Raised by _resolve_repo_diff_scope (utils.py:970) when `git merge-base <base_ref> HEAD` exits non-zero. A non-zero merge-base means git could not compute a common ancestor: the base ref does not exist locally, the histories are unrelated, or the shallow boundary cuts the ancestry. The message embeds git's stderr when present, else advises fetching base history.

Source

Thrown at strix/interface/utils.py:970

) -> RepoDiffScope:
    source_path = source.get("source_path", "")
    workspace_subdir = source.get("workspace_subdir")
    repo_path = Path(source_path)

    if not _is_git_repo(repo_path):
        raise ValueError(f"Source is not a git repository: {source_path}")

    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",

View on GitHub (pinned to 8551339130)

Solutions

  1. Fetch the base explicitly: git fetch origin main, then use --diff-base origin/main
  2. Verify the ref exists: git rev-parse --verify <base>; fix typos (main vs master, missing origin/ prefix)
  3. If histories are genuinely unrelated, pick a base within the same history or drop diff-scope
  4. Ensure the clone is not shallow at the boundary (git fetch --unshallow) so the ancestor is reachable

Example fix

# before
strix -t . --diff-scope --diff-base origin/main  # origin/main never fetched
# ValueError: Unable to compute merge-base ...

# after
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)
if r.returncode != 0:
    raise SystemExit(f"base {base_ref} unreachable; git fetch origin <branch> first")

Type guard

def merge_base_resolvable(repo: str, base_ref: str) -> bool:
    import subprocess
    return subprocess.run(["git", "-C", repo, "rev-parse", "--verify", base_ref], capture_output=True).returncode == 0

Try / catch

try:
    run_diff_scope_scan()
except ValueError as e:
    if "Unable to compute merge-base" in str(e):
        subprocess.run(["git", "-C", repo, "fetch", "origin", default_branch], check=True)
        run_with_explicit_base(f"origin/{default_branch}")
    else:
        raise

Prevention

When it happens

Trigger: Passing --diff-base pointing to a ref never fetched (e.g. origin/main when only a feature branch was cloned with --single-branch); unrelated histories (base from a different repo); a base ref that exists but predates a shallow boundary; typo'd ref name.

Common situations: CI fetching only the PR merge ref; single-branch clones; forks where origin/main was never fetched; --diff-base main (branch not fetched) instead of origin/main; repositories with grafted/replaced history.

Related errors


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