{"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/290d5ab72cc1102813fbc0406fb186ceadabc340/src/coreclr/scripts/jitrollingbuild.py#L177-L213","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run 'git branch -r --list \"*/main\"' manually to check if any remote main branch exists.","Run 'git fetch --all' to update remote tracking branches, then retry.","If your remote's default branch is not 'main', switch to the appropriate branch name or ensure a '*/main' remote tracking branch exists.","Pass -git_hash explicitly to skip the auto-detection entirely."],"exampleFix":"# before: no remote main branch found\npython jitrollingbuild.py download\n\n# after: fetch remotes or pass hash\n# Option 1:\ngit fetch --all\npython jitrollingbuild.py download\n# Option 2:\npython jitrollingbuild.py download -git_hash abc123","handlingStrategy":"validation","validationCode":"# Check that a remote main branch exists before running auto-detection\nimport subprocess\nresult = subprocess.run(['git', 'branch', '-r', '--list', '*/main'], capture_output=True, cwd=repo_path)\nif result.returncode != 0 or not result.stdout.strip():\n    print('No remote main branch found. Run git fetch --all or pass -git_hash.')","typeGuard":"def has_remote_main(repo_path: str) -> bool:\n    result = subprocess.run(['git', 'branch', '-r', '--list', '*/main'], capture_output=True, cwd=repo_path)\n    return result.returncode == 0 and bool(result.stdout.strip())","tryCatchPattern":"try:\n    process_git_hash_arg(coreclr_args)\nexcept RuntimeError as e:\n    if \"newest 'main'\" in str(e):\n        logging.error('Run git fetch --all to update remote branches, or pass -git_hash.')\n        sys.exit(1)\n    raise","preventionTips":["Run 'git fetch --all' before invoking jitrollingbuild download/list.","Ensure the remote uses 'main' as its default branch (not 'master').","Pass -git_hash explicitly to avoid depending on remote branch state."],"tags":["git","jitrollingbuild","infrastructure","environment","remote"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}