diff --git a/git/repo/base.py b/git/repo/base.py index 1eb5fe362..a8c0b515a 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -296,6 +296,16 @@ def __init__( else: self.odb = odbt(rootpath) + # Check dubious ownership + try: + if not (self.bare or Git.is_cygwin()): + _ = self.git.status() + except GitCommandError as err: + if "detected dubious ownership" in err.stderr: + err_msg = f"Detected dubious ownership in repository at: {epath}" + raise InvalidGitRepositoryError(err_msg) from None + raise + def __enter__(self) -> "Repo": return self