source_info: include git worktree detection

Standard git repos contain a ".git" folder, however worktrees
contain a ".git" file.  The file provides the path to the worktree's
git directory.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan committed 2025-02-11 16:51:04 -05:00
1 parent 2fcc542d85
commit 706455a6f8
1 file changed
+3 -3
+3 -3
View File
@@ -32,15 +32,15 @@ def source_path() -> pathlib.Path:
def is_git_repo(src_path: Optional[pathlib.Path] = None) -> bool:
if src_path is None:
src_path = source_path()
return src_path.joinpath(".git").is_dir()
return src_path.joinpath(".git").exists()
def find_git_repo(src_path: Optional[pathlib.Path] = None) -> Optional[pathlib.Path]:
if src_path is None:
src_path = source_path()
if src_path.joinpath(".git").is_dir():
if src_path.joinpath(".git").exists():
return src_path
for parent in src_path.parents:
if parent.joinpath(".git").is_dir():
if parent.joinpath(".git").exists():
return parent
return None