{"record":{"id":"ec48241d69eb4c3f","repo":"dotnet/runtime","slug":"couldn-t-determine-current-git-hash","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/jitrollingbuild.py","lineNumber":185,"sourceCode":"    \"\"\"\n\n    if coreclr_args.git_hash is not None:\n        return\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        command = [ \"git\", \"rev-parse\", \"HEAD\" ]\n        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()","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/coreclr/scripts/jitrollingbuild.py#L167-L203","documentation":"Thrown by process_git_hash_arg() in jitrollingbuild.py when the command 'git rev-parse HEAD' returns a non-zero exit code while running inside the runtime repo root. This means the script cannot determine the current commit hash of the working tree, which is the first step in computing a baseline JIT for asm diffs.","triggerScenarios":"Called when the user runs 'jitrollingbuild.py download' or 'jitrollingbuild.py list' without an explicit -git_hash argument. The script enters ChangeDir(coreclr_args.runtime_repo_location) and runs subprocess 'git rev-parse HEAD'. If proc.returncode != 0, the RuntimeError is raised at line 185.","commonSituations":"The script is invoked from a directory that is not a git repository (or runtime_repo_location is misconfigured). The .git directory is corrupted or locked. Git is not installed or not on PATH. The repository is in a detached HEAD state with unusual conditions that confuse rev-parse.","solutions":["Verify you are running from within a clone of the dotnet/runtime repo and that runtime_repo_location points to the repo root.","Run 'git rev-parse HEAD' manually in the repo root to see the exact git error.","Ensure git is installed and accessible on PATH; check 'git --version'.","If you know the exact hash you want, pass it explicitly with -git_hash to bypass the auto-detection logic."],"exampleFix":"# before: auto-detection fails because not in a git repo\npython jitrollingbuild.py download\n\n# after: pass hash explicitly\npython jitrollingbuild.py download -git_hash abc123def456","handlingStrategy":"try-catch","validationCode":"# Validate git repo state before running jitrollingbuild\nimport subprocess\ndef is_valid_git_repo(repo_path):\n    result = subprocess.run(['git', 'rev-parse', 'HEAD'], capture_output=True, cwd=repo_path)\n    return result.returncode == 0\n\n# Usage before calling:\nif not is_valid_git_repo(coreclr_args.runtime_repo_location):\n    print('Not a valid git repo; pass -git_hash explicitly')","typeGuard":"def has_valid_head(repo_path: str) -> bool:\n    try:\n        result = subprocess.run(['git', 'rev-parse', 'HEAD'], capture_output=True, cwd=repo_path, timeout=10)\n        return result.returncode == 0\n    except Exception:\n        return False","tryCatchPattern":"try:\n    process_git_hash_arg(coreclr_args)\nexcept RuntimeError as e:\n    if 'current git hash' in str(e):\n        logging.error('Git repo issue. Pass -git_hash explicitly to bypass auto-detection.')\n        sys.exit(1)\n    raise","preventionTips":["Always run jitrollingbuild from within the dotnet/runtime repo root.","Verify 'git rev-parse HEAD' works before invoking the script.","Pass -git_hash explicitly in CI or automated environments where git state may be unusual."],"tags":["git","jitrollingbuild","infrastructure","environment"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}