dotnet/runtime · error · RuntimeError

Couldn't determine newest 'main' git hash

Error message

Couldn't determine newest 'main' git hash

What it means

Thrown by process_git_hash_arg() when 'git branch -r --sort=-committerdate -v --list */main' returns a non-zero exit code. The script needs to find the newest remote 'main' branch commit to compute a merge-base baseline against the current HEAD. This step identifies where the current branch diverged from main.

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 290d5ab72c)

Solutions

  1. Run 'git branch -r --list "*/main"' manually to check if any remote main branch exists.
  2. Run 'git fetch --all' to update remote tracking branches, then retry.
  3. If your remote's default branch is not 'main', switch to the appropriate branch name or ensure a '*/main' remote tracking branch exists.
  4. Pass -git_hash explicitly to skip the auto-detection entirely.

Example fix

# before: no remote main branch found
python jitrollingbuild.py download

# after: fetch remotes or pass hash
# Option 1:
git fetch --all
python jitrollingbuild.py download
# Option 2:
python jitrollingbuild.py download -git_hash abc123
Defensive patterns

Strategy: validation

Validate before calling

# Check that a remote main branch exists before running auto-detection
import subprocess
result = subprocess.run(['git', 'branch', '-r', '--list', '*/main'], capture_output=True, cwd=repo_path)
if result.returncode != 0 or not result.stdout.strip():
    print('No remote main branch found. Run git fetch --all or pass -git_hash.')

Type guard

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

Try / catch

try:
    process_git_hash_arg(coreclr_args)
except RuntimeError as e:
    if "newest 'main'" in str(e):
        logging.error('Run git fetch --all to update remote branches, or pass -git_hash.')
        sys.exit(1)
    raise

Prevention

When it happens

Trigger: Called during auto-detection of the baseline JIT hash (no explicit -git_hash). After successfully getting the current hash via 'git rev-parse HEAD', the script queries for remote main branches. If git returns a non-zero code, the RuntimeError is raised at line 195.

Common situations: The local clone has no remote tracking branches named '*/main' (e.g., the remote is named 'origin' but the default branch is 'master' not 'main', or remotes haven't been fetched). Network issues prevented fetching remote refs. The repo was created with a shallow clone or worktree that lacks remote branch metadata.

Related errors


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