Commit ab66bb9d by finswimmer Committed by GitHub

get_vcs starts searching git folder from tmp dir instead of project (#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`
parent 90af3a46
...@@ -44,6 +44,7 @@ class Builder(object): ...@@ -44,6 +44,7 @@ class Builder(object):
self._io = io self._io = io
self._package = poetry.package self._package = poetry.package
self._path = poetry.file.parent self._path = poetry.file.parent
self._original_path = self._path
packages = [] packages = []
for p in self._package.packages: for p in self._package.packages:
...@@ -75,7 +76,7 @@ class Builder(object): ...@@ -75,7 +76,7 @@ class Builder(object):
@lru_cache(maxsize=None) @lru_cache(maxsize=None)
def find_excluded_files(self): # type: () -> Set[str] def find_excluded_files(self): # type: () -> Set[str]
# Checking VCS # Checking VCS
vcs = get_vcs(self._path) vcs = get_vcs(self._original_path)
if not vcs: if not vcs:
vcs_ignored_files = set() vcs_ignored_files = set()
else: else:
......
import os
import subprocess import subprocess
import warnings
from poetry.utils._compat import Path from poetry.utils._compat import Path
from poetry.utils._compat import decode
from .git import Git from .git import Git
def get_vcs(directory): # type: (Path) -> Git def get_vcs(directory): # type: (Path) -> Git
directory = directory.resolve() working_dir = Path.cwd()
os.chdir(str(directory.resolve()))
for p in [directory] + list(directory.parents):
if (p / ".git").is_dir(): try:
try: git_dir = decode(
return Git(p) subprocess.check_output(
except (subprocess.CalledProcessError, OSError): ["git", "rev-parse", "--show-toplevel"], stderr=subprocess.STDOUT
# Either git could not be found or does not exist )
warnings.warn( ).strip()
"git executable could not be found", category=RuntimeWarning
) vcs = Git(Path(git_dir))
return except subprocess.CalledProcessError:
vcs = None
finally:
os.chdir(str(working_dir))
return vcs
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment