{"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/60108ba66eb7d1d12f595480091b4ad80a24b172/src/coreclr/scripts/superpmi.py#L4863-L4899","documentation":"Raised by determine_base_jit when 'git branch -r --sort=-committerdate -v --list */main' returns nonzero. This command finds the newest remote 'main' branch tip, from which the merge-base (baseline) is computed. A failure means git could not enumerate remote branches, typically because there are no remotes, the network is unreachable, or the repo has no */main remote branch.","triggerScenarios":"subprocess.Popen(['git','branch','-r','--sort=-committerdate','-v','--list','*/main']) returns nonzero. Occurs in a shallow or local-only clone with no remotes configured, when 'origin/main' (or any */main) does not exist, when offline and refs are missing, or after a history rewrite that removed main.","commonSituations":"Cloning from a fork whose default branch is not 'main'; a local-only repo (no origin); offline run before fetching remote refs; a repo where main was renamed; CI checkout that only fetched a single branch.","solutions":["Ensure a remote named 'origin' (or other) with a 'main' branch exists: run 'git -C <repo> branch -r --list */main' and verify output.","Run 'git fetch origin' to populate remote refs before invoking superpmi.py.","Pass --base_git_hash <sha> explicitly to bypass the auto-detection of the baseline.","If your default branch differs, create or track a remote 'main' ref."],"exampleFix":"// before\ncommand = [\"git\", \"branch\", \"-r\", \"--sort=-committerdate\", \"-v\", \"--list\", \"*/main\"]\nproc = subprocess.Popen(command, stdout=subprocess.PIPE)\nstdout_git_main_branch, _ = proc.communicate()\nif proc.returncode != 0:\n    raise RuntimeError(\"Couldn't determine newest 'main' git hash\")\n// after (fix invocation)\ngit -C <repo> fetch origin\n# Or pass the baseline directly:\npython superpmi.py asmdiff --base_git_hash <baseline-sha> ...","handlingStrategy":"validation","validationCode":"import subprocess\ndef validate_main_branch(repo_location):\n    proc = subprocess.run(['git', '-C', repo_location, 'branch', '-r', '--sort=-committerdate', '-v', '--list', '*/main'], capture_output=True)\n    if proc.returncode != 0:\n        raise RuntimeError(f\"git branch -r --list '*/main' failed in {repo_location}: {proc.stderr.decode('utf-8','replace').strip()}\")\n    out = proc.stdout.decode('utf-8').strip()\n    if not out:\n        raise RuntimeError(f\"No remote '*/main' branch found in {repo_location}; run 'git fetch origin' or pass --base_git_hash\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fetch remote refs ('git fetch origin') before running baseline detection.","Ensure a remote branch named 'main' exists.","Pass --base_git_hash to bypass auto-detection in offline or fork scenarios."],"tags":["git","base-jit","subprocess","network","superpmi","asmdiff"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}