{"record":{"id":"b1c87862ccbb3ec5","repo":"dotnet/runtime","slug":"couldn-t-determine-newest-main-git-hash-b1c878","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/superpmi.py","lineNumber":4881,"sourceCode":"            return_code = proc.returncode\n            if return_code == 0:\n                current_hash = stdout_git_rev_parse.decode('utf-8').strip()\n                logging.debug(\"Current hash: %s\", current_hash)\n            else:\n                raise RuntimeError(\"Couldn't determine current git hash\")\n        else:\n            current_hash = coreclr_args.git_hash\n\n        if coreclr_args.base_git_hash is None:\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        else:\n            baseline_hash = coreclr_args.base_git_hash\n\n        if coreclr_args.base_git_hash is None:","sourceCodeStart":4863,"sourceCodeEnd":4899,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/coreclr/scripts/superpmi.py#L4863-L4899","documentation":"Raised by get_baseline_jit when `git branch -r --sort=-committerdate -v --list */main` exits non-zero. The script needs the newest remote main hash to compute a merge-base as the baseline; without it the baseline cannot be derived.","triggerScenarios":"The runtime repo has no remote, no `*/main` remote-tracking branch, or the remote/refs are not fetched. Fires only when --base_git_hash is omitted.","commonSituations":"Cloning with `--no-remote`, a local-only clone with detached HEAD, working on a fork whose default branch is `master` not `main`, or `git fetch` never run so origin/main is absent.","solutions":["Add/refresh the remote: `git remote add origin https://github.com/dotnet/runtime && git fetch origin`.","Confirm a `*/main` ref exists: `git branch -r --list '*/main'`.","Bypass detection with `--base_git_hash <commit>`.","If the default branch differs, switch the working branch to track origin/main."],"exampleFix":"// before\n# raises [181] because no origin/main\n// after\ngit fetch origin && python superpmi.py ...\n# or\npython superpmi.py --base_git_hash <baseline-commit> ...","handlingStrategy":"validation","validationCode":"import subprocess\nout = subprocess.run(['git','branch','-r','--list','*/main'], cwd=runtime_repo_location, capture_output=True, text=True)\nif out.returncode != 0 or not out.stdout.strip():\n    raise SystemExit('no origin/main fetched; run `git fetch origin` first')","typeGuard":"def has_remote_main(path: str) -> bool:\n    import subprocess\n    out = subprocess.run(['git','branch','-r','--list','*/main'], cwd=path, capture_output=True, text=True)\n    return out.returncode == 0 and bool(out.stdout.strip())","tryCatchPattern":"try:\n    main(...)\nexcept RuntimeError as e:\n    if \"newest 'main'\" in str(e):\n        subprocess.run(['git','fetch','origin'], cwd=runtime_repo_location, check=True)\n        main(...)  # or pass --base_git_hash","preventionTips":["Ensure `git fetch origin` ran before superpmi","Pass --base_git_hash in automation","Fork default branch should be main, not master"],"tags":["git","superpmi","environment"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}