get_vcs: improve Cygwin git support under Windows#704
Merged
abn merged 3 commits intopython-poetry:mainfrom Feb 26, 2024
Merged
get_vcs: improve Cygwin git support under Windows#704abn merged 3 commits intopython-poetry:mainfrom
abn merged 3 commits intopython-poetry:mainfrom
Conversation
Cover more cases: * that get_vcs() actually returns the git root path * finding the git dir from a subdirectory * git not finding a git repo * a gitignored directory not being found
In MSYS2 we currently use cygwin git which returns/prints unix paths. For example "rev-parse --show-toplevel" returns absolute paths which Windows CPython doesn't understand, and thus get_vcs() fails to find the git repo root. Instead of using "--show-toplevel" which returns the absolute path to the git root, we can just use "--show-cdup" which returns the relative path from the current working directory to the git root, for example "../" in a repo subdirectory. Since this is a relative path it's also valid as a Windows path, and combined with the working directory we get the git root, the same as before.
5e14403 to
b2d7575
Compare
It's not needed to change global state here, just change the working directory of the child processes instead. Since os.chdir() raised for non-existing paths, keep that behaviour by passing strict to resolve().
b2d7575 to
869605c
Compare
|
abn
approved these changes
Feb 26, 2024
Contributor
Author
|
thanks! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



(I haven't created an issue since the issue template suggested to skip it, but I can create one if wanted)
In MSYS2 we currently use native Python in combination with cygwin git, the former working with Windows paths, while the latter returns Unix paths, which means get_vcs() will find a git repo, but with a bogus git directory.
It's quite easy to fix by using git in a way so it returns relative paths, without adding any special cases.
See the separate commits for details.
This makes the test suite 100% pass under MSYS2.