Skip to content

Commit

Permalink
Prevent matching bogus parent git directories
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshilliard committed Jul 8, 2023
1 parent 5d3abc5 commit f69283b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/poetry/core/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f69283b

Please sign in to comment.