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 process_git_hash_arg() in jitrollingbuild.py when 'git branch -r --sort=-committerdate -v --list "*/main"' fails. This command lists remote branches matching */main sorted by most recent commit, to find the newest main branch hash from any remote. The newest main hash is needed to compute the merge-base (baseline) for JIT change detection.

Solutions

  1. Check if the repository has a remote main branch: run 'git branch -r --list */main' manually.
  2. If the default branch is 'master', the script may need updating, or rename your branch to 'main'.
  3. Run 'git fetch --all' to ensure remote branches are available.
  4. Verify remotes are configured with 'git remote -v'.
  5. Pass -git_hash explicitly to skip auto-detection.

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()
return_code = proc.returncode
if return_code != 0:
    raise RuntimeError("Couldn't determine newest 'main' git hash")

# after - try 'main' then fall back to 'master'
for branch_pattern in ["*/main", "*/master"]:
    command = ["git", "branch", "-r", "--sort=-committerdate", "-v", "--list", branch_pattern]
    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout_git_main_branch, _ = proc.communicate()
    if proc.returncode == 0 and stdout_git_main_branch.strip():
        break
else:
    raise RuntimeError("Couldn't determine newest 'main' or 'master' git hash")
Defensive patterns

Strategy: validation

Validate before calling

import subprocess

def can_find_main_branch(repo_path: str) -> bool:
    """Check if any remote has a 'main' branch."""
    result = subprocess.run(
        ['git', 'branch', '-r', '--list', '*/main'],
        cwd=repo_path, capture_output=True)
    return result.returncode == 0 and bool(result.stdout.strip())

# Usage:
if not can_find_main_branch(repo_path):
    print("No remote 'main' branch found. Try 'git fetch --all' or pass -git_hash.")
    # Could also check for */master as fallback

Type guard

null

Try / catch

try:
    process_git_hash_arg(coreclr_args)
except RuntimeError as e:
    if "newest 'main'" in str(e):
        logging.error(f"{e}. Check if remote main branch exists with 'git branch -r'.")
        logging.error("You may need to 'git fetch --all' or pass -git_hash explicitly.")
    raise

Prevention

When it happens

Trigger: Triggered when the git branch listing command returns a non-zero exit code. This can happen if there are no remotes configured, if no remote has a 'main' branch (e.g., the default branch is 'master'), if git is in a broken state, or if the repository has no remote tracking branches fetched yet.

Common situations: The repository's default branch is 'master' not 'main' (common in older clones or forks). The remote branches haven't been fetched (shallow clone or fresh clone without fetch). No remotes are configured. The branch was renamed but the script wasn't updated.

Related errors


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

Appendix: source

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

        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()
        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)

        # Enumerate the last 20 changes, starting with the baseline, that included JIT and JIT-EE GUID changes.
        command = [ "git", "log", "--pretty=format:%H", baseline_hash, "-20", "--", "src/coreclr/jit/*", "src/coreclr/inc/jiteeversionguid.h" ]
        logging.debug("Invoking: {}".format(" ".join(command)))

View on GitHub (pinned to 60108ba66e)