Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_vcs starts searching git folder from tmp dir instead of project (#1946) #1947

Merged
merged 4 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion poetry/masonry/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(
self._io = io
self._package = poetry.package
self._path = poetry.file.parent
self._original_path = self._path

packages = []
for p in self._package.packages:
Expand Down Expand Up @@ -75,7 +76,7 @@ def build(self):
@lru_cache(maxsize=None)
def find_excluded_files(self): # type: () -> Set[str]
# Checking VCS
vcs = get_vcs(self._path)
vcs = get_vcs(self._original_path)
if not vcs:
vcs_ignored_files = set()
else:
Expand Down
34 changes: 20 additions & 14 deletions poetry/vcs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import os
import subprocess
import warnings

from poetry.utils._compat import Path
from poetry.utils._compat import decode

from .git import Git


def get_vcs(directory): # type: (Path) -> Git
directory = directory.resolve()

for p in [directory] + list(directory.parents):
if (p / ".git").is_dir():
try:
return Git(p)
except (subprocess.CalledProcessError, OSError):
# Either git could not be found or does not exist
warnings.warn(
"git executable could not be found", category=RuntimeWarning
)

return
working_dir = Path.cwd()
os.chdir(str(directory.resolve()))

try:
git_dir = decode(
subprocess.check_output(
["git", "rev-parse", "--show-toplevel"], stderr=subprocess.STDOUT
)
).strip()

vcs = Git(Path(git_dir))

except subprocess.CalledProcessError:
vcs = None
finally:
os.chdir(str(working_dir))

return vcs