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