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 determine_base_jit when 'git branch -r --sort=-committerdate -v --list */main' returns nonzero. This command finds the newest remote 'main' branch tip, from which the merge-base (baseline) is computed. A failure means git could not enumerate remote branches, typically because there are no remotes, the network is unreachable, or the repo has no */main remote branch.

Solutions

  1. Ensure a remote named 'origin' (or other) with a 'main' branch exists: run 'git -C <repo> branch -r --list */main' and verify output.
  2. Run 'git fetch origin' to populate remote refs before invoking superpmi.py.
  3. Pass --base_git_hash <sha> explicitly to bypass the auto-detection of the baseline.
  4. If your default branch differs, create or track a remote 'main' ref.

Example fix

// before
command = ["git", "branch", "-r", "--sort=-committerdate", "-v", "--list", "*/main"]
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
stdout_git_main_branch, _ = proc.communicate()
if proc.returncode != 0:
    raise RuntimeError("Couldn't determine newest 'main' git hash")
// after (fix invocation)
git -C <repo> fetch origin
# Or pass the baseline directly:
python superpmi.py asmdiff --base_git_hash <baseline-sha> ...
Defensive patterns

Strategy: validation

Validate before calling

import subprocess
def validate_main_branch(repo_location):
    proc = subprocess.run(['git', '-C', repo_location, 'branch', '-r', '--sort=-committerdate', '-v', '--list', '*/main'], capture_output=True)
    if proc.returncode != 0:
        raise RuntimeError(f"git branch -r --list '*/main' failed in {repo_location}: {proc.stderr.decode('utf-8','replace').strip()}")
    out = proc.stdout.decode('utf-8').strip()
    if not out:
        raise RuntimeError(f"No remote '*/main' branch found in {repo_location}; run 'git fetch origin' or pass --base_git_hash")

Prevention

When it happens

Trigger: subprocess.Popen(['git','branch','-r','--sort=-committerdate','-v','--list','*/main']) returns nonzero. Occurs in a shallow or local-only clone with no remotes configured, when 'origin/main' (or any */main) does not exist, when offline and refs are missing, or after a history rewrite that removed main.

Common situations: Cloning from a fork whose default branch is not 'main'; a local-only repo (no origin); offline run before fetching remote refs; a repo where main was renamed; CI checkout that only fetched a single branch.

Related errors


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

Appendix: 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 60108ba66e)