dotnet/runtime · error · RuntimeError

Couldn't determine current git hash

Error message

Couldn't determine current git hash

What it means

Thrown by process_git_hash_arg() in jitrollingbuild.py when the command 'git rev-parse HEAD' returns a non-zero exit code while running inside the runtime repo root. This means the script cannot determine the current commit hash of the working tree, which is the first step in computing a baseline JIT for asm diffs.

Source

Thrown at src/coreclr/scripts/jitrollingbuild.py:185

    """

    if coreclr_args.git_hash is not None:
        return

    # 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):
        command = [ "git", "rev-parse", "HEAD" ]
        logging.debug("Invoking: {}".format(" ".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.info("Current hash: {}".format(current_hash))
        else:
            raise RuntimeError("Couldn't determine current git hash")

        # 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 ]
        logging.debug("Invoking: %s", " ".join(command))
        proc = subprocess.Popen(command, stdout=subprocess.PIPE)
        stdout_git_merge_base, _ = proc.communicate()

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Verify you are running from within a clone of the dotnet/runtime repo and that runtime_repo_location points to the repo root.
  2. Run 'git rev-parse HEAD' manually in the repo root to see the exact git error.
  3. Ensure git is installed and accessible on PATH; check 'git --version'.
  4. If you know the exact hash you want, pass it explicitly with -git_hash to bypass the auto-detection logic.

Example fix

# before: auto-detection fails because not in a git repo
python jitrollingbuild.py download

# after: pass hash explicitly
python jitrollingbuild.py download -git_hash abc123def456
Defensive patterns

Strategy: try-catch

Validate before calling

# Validate git repo state before running jitrollingbuild
import subprocess
def is_valid_git_repo(repo_path):
    result = subprocess.run(['git', 'rev-parse', 'HEAD'], capture_output=True, cwd=repo_path)
    return result.returncode == 0

# Usage before calling:
if not is_valid_git_repo(coreclr_args.runtime_repo_location):
    print('Not a valid git repo; pass -git_hash explicitly')

Type guard

def has_valid_head(repo_path: str) -> bool:
    try:
        result = subprocess.run(['git', 'rev-parse', 'HEAD'], capture_output=True, cwd=repo_path, timeout=10)
        return result.returncode == 0
    except Exception:
        return False

Try / catch

try:
    process_git_hash_arg(coreclr_args)
except RuntimeError as e:
    if 'current git hash' in str(e):
        logging.error('Git repo issue. Pass -git_hash explicitly to bypass auto-detection.')
        sys.exit(1)
    raise

Prevention

When it happens

Trigger: Called when the user runs 'jitrollingbuild.py download' or 'jitrollingbuild.py list' without an explicit -git_hash argument. The script enters ChangeDir(coreclr_args.runtime_repo_location) and runs subprocess 'git rev-parse HEAD'. If proc.returncode != 0, the RuntimeError is raised at line 185.

Common situations: The script is invoked from a directory that is not a git repository (or runtime_repo_location is misconfigured). The .git directory is corrupted or locked. Git is not installed or not on PATH. The repository is in a detached HEAD state with unusual conditions that confuse rev-parse.

Related errors


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