From a1a05a85f226a7d6f06c820e8111dd7dc07876ab Mon Sep 17 00:00:00 2001 From: James Hilliard Date: Mon, 26 Jun 2023 23:45:45 -0600 Subject: [PATCH] Prevent matching bogus parent git directories --- src/poetry/core/vcs/__init__.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/poetry/core/vcs/__init__.py b/src/poetry/core/vcs/__init__.py index 4e03a8904..debd95760 100644 --- a/src/poetry/core/vcs/__init__.py +++ b/src/poetry/core/vcs/__init__.py @@ -17,13 +17,20 @@ def get_vcs(directory: Path) -> Git | None: try: from poetry.core.vcs.git import executable - git_dir = subprocess.check_output( - [executable(), "rev-parse", "--show-toplevel"], - stderr=subprocess.STDOUT, - text=True, - ).strip() - - vcs = Git(Path(git_dir)) + check_ignore = subprocess.run( + [executable(), "check-ignore", "."], + ).returncode + + if check_ignore == 0: + vcs = None + else: + git_dir = subprocess.check_output( + [executable(), "rev-parse", "--show-toplevel"], + stderr=subprocess.STDOUT, + text=True, + ).strip() + + vcs = Git(Path(git_dir)) except (subprocess.CalledProcessError, OSError, RuntimeError): vcs = None