- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 934
Different behavior between repo.remote().url and repo.remote().urls when dealing with UNC paths #1019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks a lot for posting this here! I had a quick look and believe the reason is the following: When asking for When asking for The issue seems to be stemming from GitPython incorrectly transforming the UNC path, potentially treating it like some sort of Linux path. |
So seems it would make sense for each function to access the url in the same way. Do we have a preference? Should the |
I think it does make sense that their output is consistent, with Since calling implementing |
Sorry for the |
Entry from the actual git config file looks like this:
It looks like gitpython implements its own configparser inherited from configparser's RawConfigParser, including its own This appears to be where the path is getting messed up. Opening the file using the |
Thanks for the research! This means that if we would use The reason the file is read as binary is that otherwise, the operating system (or Python, maybe) makes assumptions about the encoding of the text file, even though git itself doesn't know or care. Therefore reads can fail even though otherwise they won't. GitPython obviously tries to decode the file as UTF-8 effectively on a line-by-line basis, which may fail as well so it isn't necessarily better. Something I don't understand is how "RT" can clean up a path like "\\path\dir" into "\path\dir", which seems way more than a decoder would ever do. In a way, I don't even understand why such a path would be written in the first place, unless backslash is a reserved character in git config files. |
So, escape characters on different platforms and encodings make my head spin, but I expect this is a windows-only problem due to windows use of backslashes in paths. Even on a local repo, with no UNC complications, it looks like (under a utf-8 lens) git adds extra escape backslashes. So the entry in the config file looks like this in binary: So, I'm not sure that the gitpython configparser is decoding as utf-8. I'm still trying to follow the config lines through, but that's my best guess at this point. |
I forgot to include, I think the reason the |
Awesome! What would that mean for a fix? Doesn't that mean that one could simply decode with 'unicode-escape' instead? I couldn't really find details on what's expected of git configuration files, but would have wanted to post this here to verify the solution above would be acceptable. |
Yeah, I know what you mean about the git configuration files. I went looking for something also, but couldn't find anything. We could potentially decode with |
Sometimes one has to dig deeper :D, so I found this portion of the git source code which seems to mean that it's simply decoding these with Thus for us it might indeed be safest to do an additional processing step, as you suggest. As git itself is also doing it, it might not even be 'hacky' after all. If you would like to give it a shot, I would very much welcome a PR to start hammering home a fix. |
Not sure if this is specifically realted to UNC paths or not, but here is what I'm observing.
Clone a repo from a networked server to your local machine. Then:
whereas:
Thanks!
The text was updated successfully, but these errors were encountered: