Get current git commit hash. Searches parent directories to support monorepo subdirectories. Args: repo_path: Path inside a git repository Returns: Commit hash or empty string if not in a git repo
(repo_path: Path)
| 150 | def get_git_commit_hash(repo_path: Path) -> str: |
| 151 | """ |
| 152 | Get current git commit hash. |
| 153 | |
| 154 | Searches parent directories to support monorepo subdirectories. |
| 155 | |
| 156 | Args: |
| 157 | repo_path: Path inside a git repository |
| 158 | |
| 159 | Returns: |
| 160 | Commit hash or empty string if not in a git repo |
| 161 | """ |
| 162 | repo = _get_git_repo(repo_path) |
| 163 | if repo is None: |
| 164 | return "" |
| 165 | |
| 166 | try: |
| 167 | return repo.head.commit.hexsha |
| 168 | except Exception: # noqa: BLE001 — commit info is optional metadata |
| 169 | return "" |
| 170 | |
| 171 | |
| 172 | def get_git_branch(repo_path: Path) -> str: |
| 173 | """ |
| 174 | Get current git branch name. |
no test coverage detected