{"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/60108ba66eb7d1d12f595480091b4ad80a24b172/src/coreclr/scripts/superpmi.py#L4850-L4886","documentation":"Raised by determine_base_jit when 'git rev-parse HEAD' returns a nonzero exit code while running inside the runtime repo root (ChangeDir to runtime_repo_location). The current hash identifies the diff-side commit; without it, baseline computation cannot proceed. A nonzero code means git is unavailable, the directory is not a git repo, or the repo is in a broken state.","triggerScenarios":"subprocess.Popen(['git','rev-parse','HEAD']) runs and proc.returncode != 0, inside the runtime_repo_location. Happens when runtime_repo_location is not a git checkout, git is not installed/on PATH, the .git directory is missing/corrupt, or HEAD is unborn (empty repo after init with no commits).","commonSituations":"Downloading a source tarball instead of a git clone (no .git); running in a stripped container without git; pointing --runtime_repo_location at the wrong directory; a fresh repo with no commits.","solutions":["Confirm runtime_repo_location is a valid git clone: run 'git -C <runtime_repo_location> rev-parse HEAD' and ensure it succeeds.","Ensure git is installed and on PATH in the execution environment.","Clone the runtime repo via git rather than extracting a tarball so .git history exists.","Pass --git_hash <sha> explicitly to skip the rev-parse step if you know the current commit."],"exampleFix":"// before\ncommand = [\"git\", \"rev-parse\", \"HEAD\"]\nproc = subprocess.Popen(command, stdout=subprocess.PIPE)\nstdout_git_rev_parse, _ = proc.communicate()\nif proc.returncode != 0:\n    raise RuntimeError(\"Couldn't determine current git hash\")\n// after (fix invocation)\ngit -C <runtime_repo_location> rev-parse HEAD   # must succeed\n# Or pass the hash explicitly:\npython superpmi.py asmdiff --git_hash <sha> ...","handlingStrategy":"validation","validationCode":"import subprocess, shutil\ndef validate_git_head(repo_location):\n    if shutil.which('git') is None:\n        raise RuntimeError('git is not installed or not on PATH')\n    proc = subprocess.run(['git', '-C', repo_location, 'rev-parse', 'HEAD'], capture_output=True)\n    if proc.returncode != 0:\n        raise RuntimeError(f\"git rev-parse HEAD failed in {repo_location}: {proc.stderr.decode('utf-8','replace').strip()}\")\n    return proc.stdout.decode('utf-8').strip()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure runtime_repo_location is a real git clone (not a tarball extract).","Keep git installed and on PATH in CI containers.","Pass --git_hash explicitly to bypass rev-parse when history is known."],"tags":["git","base-jit","subprocess","superpmi","asmdiff"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}