source_info: add within_git_repo method

Check for git files and folders, including those of parents.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2023-06-20 08:08:30 -04:00
parent 86af3a42ff
commit 35396a5b2a
No known key found for this signature in database
GPG Key ID: 5A1EB336DFB4C71B
1 changed files with 11 additions and 1 deletions

View File

@ -23,9 +23,19 @@ def source_path() -> pathlib.Path:
def is_git_repo(src_path: Optional[pathlib.Path] = None) -> bool:
if src_path is None:
return source_path().joinpath(".git").is_dir()
src_path = source_path()
return src_path.joinpath(".git").is_dir()
def within_git_repo(src_path: Optional[pathlib.Path] = None) -> bool:
if src_path is None:
src_path = source_path()
if src_path.joinpath(".git").is_dir():
return True
for parent in src_path.parents:
if parent.joinpath(".git").is_dir():
return True
return False
def is_dist_package(src_path: Optional[pathlib.Path] = None) -> bool:
if src_path is None:
# Check Moonraker's source path