Skip to content

Commit

Permalink
get_vcs starts searching git folder from tmp dir instead of project (#…
Browse files Browse the repository at this point in the history
…1946) (#1947)

* fix (builder): take `self._original_path` if available to find `.git` folder

* change (vcs): use `git rev-parse --show-toplevel` to find git root folder

* fix (vcs): change back to original working dir after finding vcs

* change (builder): introduce self._original_path to keep original path
if(vcs): resolve directory for `get_vcs`
  • Loading branch information
finswimmer authored Feb 28, 2020
1 parent 90af3a4 commit ab66bb9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
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:

This comment has been minimized.

Copy link
@jr314159

jr314159 Feb 28, 2020

This is apparently breaking poetry when git is not installed.

This comment has been minimized.

Copy link
@jr314159

jr314159 Feb 28, 2020

Created #2107

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

return vcs

0 comments on commit ab66bb9

Please sign in to comment.