Fix for git subdirectories#288
Fix for git subdirectories#288neersighted merged 8 commits intopython-poetry:masterfrom ashnair1:subdir-fix
Conversation
|
@finswimmer @abn Any thoughts on this? |
|
Kudos, SonarCloud Quality Gate passed!
|
|
Pinging @abn @finswimmer |
1 similar comment
|
Pinging @abn @finswimmer |
|
Hi @ashnair1 sorry about the latency. :) I need to check a couple of things downstream before reviewing this. But in the meantime can you add some test coverage? |
No problem. I've added the test case. Cheers. |
|
As mentioned in the companion PR, I've set the default language version for pre-commit to be 3.8 due to flake8-type-checking not supporting Python<3.8 |
src/poetry/core/vcs/git.py
Outdated
| formatted = re.sub(r"^git\+", "", url) | ||
| if parsed.rev: | ||
| formatted = re.sub(rf"[#@]{parsed.rev}$", "", formatted) | ||
| formatted = re.sub(rf"[#@]{parsed.rev}", "", formatted) |
There was a problem hiding this comment.
Is this a bit too greedy?
For example @subdirectory#subdirectory=library will be formatted to =library. Granted this is an edge case, but it is not beyond the possible scenarios.
There was a problem hiding this comment.
Won't this only happen if rev=subdirectory? We could just add a guard for it, but I am open to suggestions.
Oh I just got what you meant. You're right, this is a problem. Positive lookahead should fix this
formatted = re.sub(rf"[#@]{parsed.rev}(?=[#&]?)", "", formatted)
This should work except when rev="subdirectory". As I understand rev is either a commit hash or branch name so it's unlikely this would happen.
There was a problem hiding this comment.
@abn Needed a negative lookahead too to address the rev=subdirectory problem. Now it's good.
formatted = re.sub(rf"[#@]{parsed.rev}(?=[#&]?)(?!\=)", "", formatted)
There was a problem hiding this comment.
Added some additional tests to ensure expression works as expected.
|
Kudos, SonarCloud Quality Gate passed!
|








This fix is required for correctly handling git urls with subdirectory. For example consider the following url
Since the regex pattern is looking for
@revat the end, it will not strip out the revision in the above url since rev is not at the end of the string resulting in a url like this:The correct url should be the following