{"record":{"id":"20899b1da1bf2bb7","repo":"dotnet/runtime","slug":"couldn-t-determine-newest-main-git-hash","errorCode":null,"errorMessage":"Couldn't determine newest 'main' git hash","messagePattern":"Couldn't determine newest 'main' git hash","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/coreclr/scripts/jitrollingbuild.py","lineNumber":195,"sourceCode":"        logging.debug(\"Invoking: {}\".format(\" \".join(command)))\n        proc = subprocess.Popen(command, stdout=subprocess.PIPE)\n        stdout_git_rev_parse, _ = proc.communicate()\n        return_code = proc.returncode\n        if return_code == 0:\n            current_hash = stdout_git_rev_parse.decode('utf-8').strip()\n            logging.info(\"Current hash: {}\".format(current_hash))\n        else:\n            raise RuntimeError(\"Couldn't determine current git hash\")\n\n        # We've got the current hash; figure out the baseline hash.\n        # First find the newest hash for any branch matching */main.\n        command = [ \"git\", \"branch\", \"-r\", \"--sort=-committerdate\", \"-v\", \"--list\", \"*/main\" ]\n        logging.debug(\"Invoking: %s\", \" \".join(command))\n        proc = subprocess.Popen(command, stdout=subprocess.PIPE)\n        stdout_git_main_branch, _ = proc.communicate()\n        return_code = proc.returncode\n        if return_code != 0:\n            raise RuntimeError(\"Couldn't determine newest 'main' git hash\")\n\n        main_hash = stdout_git_main_branch.decode('utf-8').strip().split()[1]\n\n        # Get the merge-base between the newest main and our current rev\n        command = [ \"git\", \"merge-base\", current_hash, main_hash ]\n        logging.debug(\"Invoking: %s\", \" \".join(command))\n        proc = subprocess.Popen(command, stdout=subprocess.PIPE)\n        stdout_git_merge_base, _ = proc.communicate()\n        return_code = proc.returncode\n        if return_code != 0:\n            raise RuntimeError(\"Couldn't determine baseline git hash\")\n\n        baseline_hash = stdout_git_merge_base.decode('utf-8').strip()\n        logging.info(\"Baseline hash: %s\", baseline_hash)\n\n        # Enumerate the last 20 changes, starting with the baseline, that included JIT and JIT-EE GUID changes.\n        command = [ \"git\", \"log\", \"--pretty=format:%H\", baseline_hash, \"-20\", \"--\", \"src/coreclr/jit/*\", \"src/coreclr/inc/jiteeversionguid.h\" ]\n        logging.debug(\"Invoking: {}\".format(\" \".join(command)))","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/coreclr/scripts/jitrollingbuild.py#L177-L213","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check if the repository has a remote main branch: run 'git branch -r --list */main' manually.","If the default branch is 'master', the script may need updating, or rename your branch to 'main'.","Run 'git fetch --all' to ensure remote branches are available.","Verify remotes are configured with 'git remote -v'.","Pass -git_hash explicitly to skip auto-detection."],"exampleFix":"# before\ncommand = [\"git\", \"branch\", \"-r\", \"--sort=-committerdate\", \"-v\", \"--list\", \"*/main\"]\nproc = subprocess.Popen(command, stdout=subprocess.PIPE)\nstdout_git_main_branch, _ = proc.communicate()\nreturn_code = proc.returncode\nif return_code != 0:\n    raise RuntimeError(\"Couldn't determine newest 'main' git hash\")\n\n# after - try 'main' then fall back to 'master'\nfor branch_pattern in [\"*/main\", \"*/master\"]:\n    command = [\"git\", \"branch\", \"-r\", \"--sort=-committerdate\", \"-v\", \"--list\", branch_pattern]\n    proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n    stdout_git_main_branch, _ = proc.communicate()\n    if proc.returncode == 0 and stdout_git_main_branch.strip():\n        break\nelse:\n    raise RuntimeError(\"Couldn't determine newest 'main' or 'master' git hash\")","handlingStrategy":"validation","validationCode":"import subprocess\n\ndef can_find_main_branch(repo_path: str) -> bool:\n    \"\"\"Check if any remote has a 'main' branch.\"\"\"\n    result = subprocess.run(\n        ['git', 'branch', '-r', '--list', '*/main'],\n        cwd=repo_path, capture_output=True)\n    return result.returncode == 0 and bool(result.stdout.strip())\n\n# Usage:\nif not can_find_main_branch(repo_path):\n    print(\"No remote 'main' branch found. Try 'git fetch --all' or pass -git_hash.\")\n    # Could also check for */master as fallback","typeGuard":"null","tryCatchPattern":"try:\n    process_git_hash_arg(coreclr_args)\nexcept RuntimeError as e:\n    if \"newest 'main'\" in str(e):\n        logging.error(f\"{e}. Check if remote main branch exists with 'git branch -r'.\")\n        logging.error(\"You may need to 'git fetch --all' or pass -git_hash explicitly.\")\n    raise","preventionTips":["Ensure the repository has a remote tracking 'main' branch (fetch first).","If the repo uses 'master', consider renaming or passing -git_hash explicitly.","Run 'git fetch --all' before running the script to ensure remote refs are current.","Verify remotes are configured with 'git remote -v'."],"tags":["git","jit","rolling-build","coreclr","superpmi"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}