Return the current `HEAD` commit SHA, or `None` if unavailable. Resolved fresh on every call (unlike the branch/repo lookups): `HEAD` moves whenever the agent or user commits, checks out, or resets within a session, and each turn's trace must record the commit that was current for that
()
| 1321 | |
| 1322 | |
| 1323 | def _get_git_commit_sha() -> str | None: |
| 1324 | """Return the current `HEAD` commit SHA, or `None` if unavailable. |
| 1325 | |
| 1326 | Resolved fresh on every call (unlike the branch/repo lookups): `HEAD` moves |
| 1327 | whenever the agent or user commits, checks out, or resets within a session, |
| 1328 | and each turn's trace must record the commit that was current for that turn. |
| 1329 | """ |
| 1330 | from deepagents_code._git import resolve_git_commit_sha |
| 1331 | |
| 1332 | try: |
| 1333 | cwd = str(Path.cwd()) |
| 1334 | except OSError: |
| 1335 | logger.debug("Could not determine cwd for git commit lookup", exc_info=True) |
| 1336 | return None |
| 1337 | |
| 1338 | try: |
| 1339 | return resolve_git_commit_sha(cwd) or None |
| 1340 | except OSError: |
| 1341 | logger.debug("Could not determine git commit", exc_info=True) |
| 1342 | return None |
| 1343 | |
| 1344 | |
| 1345 | def _get_repository_metadata() -> RepositoryMetadata | None: |
no test coverage detected