| 66 | repo: Repo | None |
| 67 | |
| 68 | def __init__(self, path: str) -> None: |
| 69 | # If we have a valid repo, git_version will be a tuple |
| 70 | # of 3+ ints: (major, minor, patch, possible_additional_patch_number) |
| 71 | self.git_version: tuple[int, ...] | None = None |
| 72 | self.module: str = "" |
| 73 | |
| 74 | try: |
| 75 | import git |
| 76 | |
| 77 | self.repo = git.Repo(path, search_parent_directories=True) |
| 78 | self.git_version = self.repo.git.version_info |
| 79 | |
| 80 | if self.git_version is not None and self.git_version >= _MIN_GIT_VERSION: |
| 81 | git_root = self.repo.git.rev_parse("--show-toplevel") |
| 82 | self.module = str(os.path.relpath(path, git_root)) |
| 83 | except Exception: |
| 84 | _LOGGER.debug( |
| 85 | "Did not find a git repo at %s. This is expected if this isn't a git repo, but could " |
| 86 | "also fail for other reasons: " |
| 87 | "1) git binary or GitPython not installed " |
| 88 | "2) No .git folder " |
| 89 | "3) Corrupted .git folder " |
| 90 | "4) Path is invalid.", |
| 91 | path, |
| 92 | exc_info=True, |
| 93 | ) |
| 94 | self.repo = None |
| 95 | |
| 96 | def __repr__(self) -> str: |
| 97 | return util.repr_(self) |