MCPcopy Index your code
hub / github.com/GitGuardian/ggshield / is_valid_git_commit_ref

Function is_valid_git_commit_ref

ggshield/utils/git_shell.py:294–309  ·  view source on GitHub ↗

Check if a reference is valid and can be resolved to a commit

(ref: str, wd: Optional[Union[str, Path]] = None)

Source from the content-addressed store, hash-verified

292
293
294def 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
312def check_git_ref(ref: str, wd: Optional[Union[str, Path]] = None) -> None:

Calls 1

gitFunction · 0.85