dotnet/runtime · error · RuntimeError

Couldn't determine current git hash

Error message

Couldn't determine current git hash

What it means

Raised by get_baseline_jit in superpmi.py when `git rev-parse HEAD` exits non-zero while coreclr_args.git_hash is None. The script relies on the current HEAD to derive a baseline JIT for SuperPMI diffs, so it cannot proceed without a resolvable HEAD.

Source

Thrown at src/coreclr/scripts/superpmi.py:4868

    # We cache baseline jits under the following directory. Note that we can't create the full directory path
    # until we know the baseline JIT hash.
    default_basejit_root_dir = os.path.join(coreclr_args.spmi_location, "basejit")

    # Do all the remaining commands, including a number of 'git' commands including relative paths,
    # from the root of the runtime repo.

    with ChangeDir(coreclr_args.runtime_repo_location):
        if coreclr_args.git_hash is None:
            command = [ "git", "rev-parse", "HEAD" ]
            logging.debug("Invoking: %s", " ".join(command))
            proc = subprocess.Popen(command, stdout=subprocess.PIPE)
            stdout_git_rev_parse, _ = proc.communicate()
            return_code = proc.returncode
            if return_code == 0:
                current_hash = stdout_git_rev_parse.decode('utf-8').strip()
                logging.debug("Current hash: %s", current_hash)
            else:
                raise RuntimeError("Couldn't determine current git hash")
        else:
            current_hash = coreclr_args.git_hash

        if coreclr_args.base_git_hash is None:
            # We've got the current hash; figure out the baseline hash.
            # First find the newest hash for any branch matching */main.
            command = [ "git", "branch", "-r", "--sort=-committerdate", "-v", "--list", "*/main" ]
            logging.debug("Invoking: %s", " ".join(command))
            proc = subprocess.Popen(command, stdout=subprocess.PIPE)
            stdout_git_main_branch, _ = proc.communicate()
            return_code = proc.returncode
            if return_code != 0:
                raise RuntimeError("Couldn't determine newest 'main' git hash")

            main_hash = stdout_git_main_branch.decode('utf-8').strip().split()[1]

            # Get the merge-base between the newest main and our current rev
            command = [ "git", "merge-base", current_hash, main_hash ]

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. From runtime_repo_location run `git rev-parse HEAD` yourself to confirm it resolves a hash; if it fails, fix the checkout.
  2. Pass the hash explicitly via `--git_hash <commit>` to bypass the auto-detection.
  3. Ensure the `git` executable is installed and on PATH (`which git`).
  4. Set --runtime_repo_location to the actual git clone root (the folder containing .git).

Example fix

// before
python superpmi.py ... // raises [180] outside a git repo
// after
python superpmi.py --git_hash 0123abcd ...  // or run inside the runtime clone root
Defensive patterns

Strategy: validation

Validate before calling

import subprocess, shutil
if shutil.which('git') is None:
    raise SystemExit('git not on PATH')
rc = subprocess.run(['git','rev-parse','--is-inside-work-tree'], cwd=runtime_repo_location).returncode
if rc != 0:
    raise SystemExit(f'{runtime_repo_location} is not a git checkout')

Type guard

def is_git_repo(path: str) -> bool:
    import subprocess
    return subprocess.run(['git','rev-parse','--is-inside-work-tree'], cwd=path,
                          stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0

Try / catch

try:
    main(...)
except RuntimeError as e:
    if 'current git hash' in str(e):
        # fall back to an explicit hash supplied by the caller
        run_with(--git_hash=known_hash)

Prevention

When it happens

Trigger: Running superpmi from a directory that is not a git repository, with a detached/corrupt .git, or with the git binary absent from PATH. Triggered whenever --git_hash is omitted and `subprocess.Popen(['git','rev-parse','HEAD']).returncode != 0` inside ChangeDir(runtime_repo_location).

Common situations: runtime_repo_location points at a plain source tarball/extracted archive rather than a clone; CI image lacks git; shallow clone with corrupted refs; script invoked from the wrong working directory.

Related errors


AI-assisted analysis of dotnet/runtime@290d5ab72c (2026-08-06). Data as JSON: /api/errors/98769d8cd9289283. Report an issue: GitHub.