Files
MINGW-packages/mingw-w64-python-poetry-core/0002-msys-git-support.patch
2024-02-25 21:49:17 +01:00

38 lines
1.0 KiB
Diff

--- a/src/poetry/core/vcs/__init__.py
+++ b/src/poetry/core/vcs/__init__.py
@@ -9,8 +9,7 @@
def get_vcs(directory: Path) -> Git | None:
- working_dir = Path.cwd()
- os.chdir(str(directory.resolve()))
+ cwd = str(directory.resolve())
vcs: Git | None
@@ -27,17 +26,21 @@
vcs = None
else:
git_dir = subprocess.check_output(
- [executable(), "rev-parse", "--show-toplevel"],
+ [executable(), "rev-parse", "--show-prefix"],
stderr=subprocess.STDOUT,
text=True,
+ cwd=cwd,
encoding="utf-8",
).strip()
+ git_dir = git_dir.strip()[:-1] # remove the trailing os.sep
+ if not git_dir:
+ git_dir = cwd
+ else:
+ git_dir = cwd[:-len(git_dir)]
vcs = Git(Path(git_dir))
except (subprocess.CalledProcessError, OSError, RuntimeError):
vcs = None
- finally:
- os.chdir(str(working_dir))
return vcs