Coverage for pydantic/_internal/_git.py: 73.33%
15 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-13 19:35 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-02-13 19:35 +0000
1"""Git utilities, adopted from mypy's git utilities (https://github.com/python/mypy/blob/master/mypy/git.py)."""
3from __future__ import annotations 1abcdefghijklmnopqrstuvwxyzABCDEF
5import os 1abcdefghijklmnopqrstuvwxyzABCDEF
6import subprocess 1abcdefghijklmnopqrstuvwxyzABCDEF
9def is_git_repo(dir: str) -> bool: 1abcdefghijklmnopqrstuvwxyzABCDEF
10 """Is the given directory version-controlled with git?"""
11 return os.path.exists(os.path.join(dir, '.git')) 1abcdefghijklmnopqrstuvwxyzABCDEF
14def have_git() -> bool: 1abcdefghijklmnopqrstuvwxyzABCDEF
15 """Can we run the git executable?"""
16 try: 1abcdefghijklmnopqrstuvwxyzABCDEF
17 subprocess.check_output(['git', '--help']) 1abcdefghijklmnopqrstuvwxyzABCDEF
18 return True 1abcdefghijklmnopqrstuvwxyzABCDEF
19 except subprocess.CalledProcessError:
20 return False
21 except OSError:
22 return False
25def git_revision(dir: str) -> str: 1abcdefghijklmnopqrstuvwxyzABCDEF
26 """Get the SHA-1 of the HEAD of a git repository."""
27 return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], cwd=dir).decode('utf-8').strip() 1abcdefghijklmnopqrstuvwxyzABCDEF