pypa/pip · error · ValueError
unexpected show-ref line
Error message
unexpected show-ref line: {line!r} What it means
Raised by Git.get_revision_sha() when a line of 'git show-ref' output cannot be split into exactly two whitespace-separated parts (ref_sha and ref_name). This is an internal parsing error indicating the git command produced output in an unexpected format.
Solutions
- Check your git version: 'git --version' — upgrade if significantly outdated
- Run 'git show-ref <rev>' manually in the repo to inspect the output format
- Clean the git repo state: 'git gc' or re-clone the repository
- Report a pip bug with the git version and the show-ref output if it persists
Example fix
// before pip install git+https://example.com/repo.git@some-ref // after # inspect the git output manually cd /tmp/clone && git show-ref some-ref git --version # ensure a supported git version # re-clone cleanly if the repo state is corrupt pip install --force-reinstall git+https://example.com/repo.git@some-ref
Defensive patterns
Strategy: try-catch
Type guard
def is_valid_show_ref_line(line: str) -> bool:
parts = line.split(' ')
return len(parts) == 2 and all(parts) Try / catch
try:
sha, is_branch = Git.get_revision_sha(dest, rev)
except ValueError as e:
if 'unexpected show-ref line' in str(e):
# inspect git version and output, report as environment issue
logger.error('git show-ref output unexpected: %s', e)
raise EnvironmentError(f'unsupported git version or corrupt repo: {e}')
raise Prevention
- Use a supported, up-to-date git version
- Keep the git repo clean ('git gc')
- Re-clone if the repository state is corrupt
- Report persistent issues as a pip bug with git version details
When it happens
Trigger: Calling get_revision_sha(dest, rev) where the 'git show-ref <rev>' output contains a line that does not match the expected '<sha> <refname>' two-token format. The ValueError is raised at line 173 after a failed str.split with maxsplit=2.
Common situations: A git version that changes the show-ref output format (extremely rare). A corrupted or unusual git state. A ref name containing unusual characters. Essentially an unexpected internal state — this should not occur under normal git versions.
Related errors
- Badly formatted data
- Cannot find command - invalid PATH
- {url}
- Can't verify hashes for these requirements because we don't…
- Configuration file could not be loaded.\n
AI-assisted analysis of pypa/pip@f399c37189 (2026-08-08).
Data as JSON: /api/errors/a7902a199e75dad0.
Report an issue: GitHub.
Appendix: source
Thrown at src/pip/_internal/vcs/git.py:173
cwd=dest,
show_stdout=False,
stdout_only=True,
on_returncode="ignore",
)
refs = {}
# NOTE: We do not use splitlines here since that would split on other
# unicode separators, which can be maliciously used to install a
# different revision.
for line in output.strip().split("\n"):
line = line.rstrip("\r")
if not line:
continue
try:
ref_sha, ref_name = line.split(" ", maxsplit=2)
except ValueError:
# Include the offending line to simplify troubleshooting if
# this error ever occurs.
raise ValueError(f"unexpected show-ref line: {line!r}")
refs[ref_name] = ref_sha
branch_ref = f"refs/remotes/origin/{rev}"
tag_ref = f"refs/tags/{rev}"
sha = refs.get(branch_ref)
if sha is not None:
return (sha, True)
sha = refs.get(tag_ref)
return (sha, False)
@classmethod
def _should_fetch(cls, dest: str, rev: str) -> bool:
"""
Return true if rev is a ref or is a commit that we don't have locally.View on GitHub (pinned to f399c37189)