{"record":{"id":"98769d8cd9289283","repo":"dotnet/runtime","slug":"couldn-t-determine-current-git-hash-98769d","errorCode":null,"errorMessage":"Couldn't determine current git hash","messagePattern":"Couldn't determine current git hash","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/coreclr/scripts/superpmi.py","lineNumber":4868,"sourceCode":"    # We cache baseline jits under the following directory. Note that we can't create the full directory path\n    # until we know the baseline JIT hash.\n    default_basejit_root_dir = os.path.join(coreclr_args.spmi_location, \"basejit\")\n\n    # Do all the remaining commands, including a number of 'git' commands including relative paths,\n    # from the root of the runtime repo.\n\n    with ChangeDir(coreclr_args.runtime_repo_location):\n        if coreclr_args.git_hash is None:\n            command = [ \"git\", \"rev-parse\", \"HEAD\" ]\n            logging.debug(\"Invoking: %s\", \" \".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.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 ]","sourceCodeStart":4850,"sourceCodeEnd":4886,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/coreclr/scripts/superpmi.py#L4850-L4886","documentation":"Raised by get_baseline_jit in superpmi.py when `git rev-parse HEAD` exits non-zero while coreclr_args.git_hash is None. The script relies on the current HEAD to derive a baseline JIT for SuperPMI diffs, so it cannot proceed without a resolvable HEAD.","triggerScenarios":"Running superpmi from a directory that is not a git repository, with a detached/corrupt .git, or with the git binary absent from PATH. Triggered whenever --git_hash is omitted and `subprocess.Popen(['git','rev-parse','HEAD']).returncode != 0` inside ChangeDir(runtime_repo_location).","commonSituations":"runtime_repo_location points at a plain source tarball/extracted archive rather than a clone; CI image lacks git; shallow clone with corrupted refs; script invoked from the wrong working directory.","solutions":["From runtime_repo_location run `git rev-parse HEAD` yourself to confirm it resolves a hash; if it fails, fix the checkout.","Pass the hash explicitly via `--git_hash <commit>` to bypass the auto-detection.","Ensure the `git` executable is installed and on PATH (`which git`).","Set --runtime_repo_location to the actual git clone root (the folder containing .git)."],"exampleFix":"// before\npython superpmi.py ... // raises [180] outside a git repo\n// after\npython superpmi.py --git_hash 0123abcd ...  // or run inside the runtime clone root","handlingStrategy":"validation","validationCode":"import subprocess, shutil\nif shutil.which('git') is None:\n    raise SystemExit('git not on PATH')\nrc = subprocess.run(['git','rev-parse','--is-inside-work-tree'], cwd=runtime_repo_location).returncode\nif rc != 0:\n    raise SystemExit(f'{runtime_repo_location} is not a git checkout')","typeGuard":"def is_git_repo(path: str) -> bool:\n    import subprocess\n    return subprocess.run(['git','rev-parse','--is-inside-work-tree'], cwd=path,\n                          stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0","tryCatchPattern":"try:\n    main(...)\nexcept RuntimeError as e:\n    if 'current git hash' in str(e):\n        # fall back to an explicit hash supplied by the caller\n        run_with(--git_hash=known_hash)","preventionTips":["Always invoke superpmi from the runtime clone root","Pass --git_hash in CI to make runs deterministic","Assert `git rev-parse HEAD` succeeds in a pre-step"],"tags":["git","environment","superpmi","configuration"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}