-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`
- Loading branch information
1 parent
90af3a4
commit ab66bb9
Showing
2 changed files
with
22 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
vcs = None | ||
finally: | ||
os.chdir(str(working_dir)) | ||
|
||
return vcs |
This is apparently breaking poetry when git is not installed.