Check if a reference is valid and can be resolved to a commit
(ref: str, wd: Optional[Union[str, Path]] = None)
| 292 | |
| 293 | |
| 294 | def is_valid_git_commit_ref(ref: str, wd: Optional[Union[str, Path]] = None) -> bool: |
| 295 | """ |
| 296 | Check if a reference is valid and can be resolved to a commit |
| 297 | """ |
| 298 | if not wd: |
| 299 | wd = Path.cwd() |
| 300 | |
| 301 | ref += "^{commit}" |
| 302 | cmd = ["cat-file", "-e", ref] |
| 303 | |
| 304 | try: |
| 305 | git(cmd, cwd=wd) |
| 306 | except subprocess.CalledProcessError: |
| 307 | return False |
| 308 | |
| 309 | return True |
| 310 | |
| 311 | |
| 312 | def check_git_ref(ref: str, wd: Optional[Union[str, Path]] = None) -> None: |