zed-industries/zed · error · ValueError

could not resolve ref

Error message

could not resolve ref '{ref}' against {repo_url}. Push the commit/tag, or pass a full commit SHA.

What it means

resolve_remote_ref parses `git ls-remote <repo_url> <ref>` output and prefers the peeled '^{}' entry for annotated tags. If the output contains no entries at all, the ref does not exist on the remote, and this ValueError tells you to push the commit/tag or supply a full 40-character commit SHA, which needs no ref resolution.

Solutions

  1. Push first: git push origin <branch> (and git push origin <tag> for tags)
  2. Or pass the full 40-character commit SHA, which bypasses remote ref resolution
  3. Double-check the ref spelling and that repo_url is the remote you actually pushed to
  4. For annotated tags, ensure the tag object itself is pushed, not just the commit

Example fix

# before
build_source(base_sha="feature-branch")  # ValueError: could not resolve ref 'feature-branch'

# after
git push origin feature-branch
build_source(base_sha="feature-branch")
# or skip resolution entirely:
build_source(base_sha="<full-40-char-sha>")
Defensive patterns

Strategy: validation

Validate before calling

import re, subprocess

FULL_SHA = re.compile(r"^[0-9a-fA-F]{40}$")
if not FULL_SHA.match(ref):
    listing = subprocess.run(["git", "ls-remote", repo_url, ref], capture_output=True, text=True)
    if not listing.stdout.strip():
        raise SystemExit(f"ref {ref!r} not on {repo_url}; push it or use a full 40-char SHA")

Type guard

import re

def is_full_commit_sha(ref: str) -> bool:
    return bool(re.fullmatch(r"[0-9a-fA-F]{40}", ref))

Try / catch

try:
    sha = resolve_remote_ref(repo_url, ref)
except ValueError as err:
    raise SystemExit(f"push {ref} first, or pass a full sha: {err}")

Prevention

When it happens

Trigger: Passing a branch or commit that was never pushed; giving a local-only short sha where a ref name is expected; a typo in the ref; a tag that exists locally but was never pushed; the ref living on a fork while repo_url points at upstream.

Common situations: Building an eval from a local-only branch; forgetting git push --tags; using short shas in automation; wrong remote URL after a repo migration.

Related errors


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/475b235fc7a623d3. Report an issue: GitHub.

Appendix: source

Thrown at crates/eval_cli/zed_eval/source.py:164

            repo_url,
            ref,
            f"refs/tags/{ref}",
            f"refs/heads/{ref}",
        ]
    )
    entries: list[tuple[str, str]] = []
    for line in output.splitlines():
        sha, _, name = line.partition("\t")
        if sha and name:
            entries.append((name, sha))
    # An annotated tag yields both the tag object and a peeled "<ref>^{}" entry
    # pointing at the underlying commit; the commit is what we want to build.
    for name, sha in entries:
        if name.endswith("^{}"):
            return sha
    if entries:
        return entries[0][1]
    raise ValueError(
        f"could not resolve ref '{ref}' against {repo_url}. "
        "Push the commit/tag, or pass a full commit SHA."
    )


def current_ref_name() -> str | None:
    try:
        ref_name = git_output(["rev-parse", "--abbrev-ref", "HEAD"])
    except (OSError, subprocess.CalledProcessError):
        return None
    return None if ref_name == "HEAD" else ref_name


def current_tracked_patch(base_sha: str) -> str:
    result = subprocess.run(
        ["git", "diff", "--binary", base_sha],
        cwd=repo_root(),
        check=True,

View on GitHub (pinned to f4178619ac)