dotnet/runtime · error · RuntimeError

Couldn't determine newest 'main' git hash

Error message

Couldn't determine newest 'main' git hash

What it means

Raised by get_baseline_jit when `git branch -r --sort=-committerdate -v --list */main` exits non-zero. The script needs the newest remote main hash to compute a merge-base as the baseline; without it the baseline cannot be derived.

Source

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

            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 ]
            logging.debug("Invoking: %s", " ".join(command))
            proc = subprocess.Popen(command, stdout=subprocess.PIPE)
            stdout_git_merge_base, _ = proc.communicate()
            return_code = proc.returncode
            if return_code != 0:
                raise RuntimeError("Couldn't determine baseline git hash")

            baseline_hash = stdout_git_merge_base.decode('utf-8').strip()
            logging.info("Baseline hash: %s", baseline_hash)
        else:
            baseline_hash = coreclr_args.base_git_hash

        if coreclr_args.base_git_hash is None:

View on GitHub (pinned to 290d5ab72c)

Solutions

  1. Add/refresh the remote: `git remote add origin https://github.com/dotnet/runtime && git fetch origin`.
  2. Confirm a `*/main` ref exists: `git branch -r --list '*/main'`.
  3. Bypass detection with `--base_git_hash <commit>`.
  4. If the default branch differs, switch the working branch to track origin/main.

Example fix

// before
# raises [181] because no origin/main
// after
git fetch origin && python superpmi.py ...
# or
python superpmi.py --base_git_hash <baseline-commit> ...
Defensive patterns

Strategy: validation

Validate before calling

import subprocess
out = subprocess.run(['git','branch','-r','--list','*/main'], cwd=runtime_repo_location, capture_output=True, text=True)
if out.returncode != 0 or not out.stdout.strip():
    raise SystemExit('no origin/main fetched; run `git fetch origin` first')

Type guard

def has_remote_main(path: str) -> bool:
    import subprocess
    out = subprocess.run(['git','branch','-r','--list','*/main'], cwd=path, capture_output=True, text=True)
    return out.returncode == 0 and bool(out.stdout.strip())

Try / catch

try:
    main(...)
except RuntimeError as e:
    if "newest 'main'" in str(e):
        subprocess.run(['git','fetch','origin'], cwd=runtime_repo_location, check=True)
        main(...)  # or pass --base_git_hash

Prevention

When it happens

Trigger: The runtime repo has no remote, no `*/main` remote-tracking branch, or the remote/refs are not fetched. Fires only when --base_git_hash is omitted.

Common situations: Cloning with `--no-remote`, a local-only clone with detached HEAD, working on a fork whose default branch is `master` not `main`, or `git fetch` never run so origin/main is absent.

Related errors


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