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