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):
self._io = io
self._package = poetry.package
self._path = poetry.file.parent
self._original_path = self._path
packages = []
for p in self._package.packages:
......@@ -75,7 +76,7 @@ class Builder(object):
@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:
......
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()
working_dir = Path.cwd()
os.chdir(str(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
git_dir = decode(
subprocess.check_output(
["git", "rev-parse", "--show-toplevel"], stderr=subprocess.STDOUT
)
).strip()
return
vcs = Git(Path(git_dir))
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