-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
URL substitution via insteadOf broken when NewEndpointFromCloneURL is used #5528
Comments
Hey, thanks for the report and analysis. I haven't been able to craft a reproduction test case yet, with or without setting |
So on the one hand I can see this behaviour with a fairly simple modification of one of our basic config tests, something like:
Whereas if we add a line here which looks like the following: ep.Url = e.ReplaceUrlAlias(operation, ep.Url) then we get different results, more in line with what you were suggesting:
That said, upon reflection I have a few concerns about introducing this change or something like it. The first is that since at least 2016 the Git LFS API documentation has stated that:
So at a minimum we'd have to add to the specification to indicate that we might further rewrite the constructed URL according to any That leads to my second concern, which is when and how to perform this rewriting. Git itself generally only performs one URL rewriting pass (so a chain of At the moment, as was noted in the issue description, we perform the rewriting early, on whatever string we received from Third, there's already a way to achieve the desired result and override the URL which Git LFS would otherwise construct by configuring a
Moreover, that Given the above, I'm inclined to think we should not alter the existing behaviour, but advise users who want to customize the server URLs constructed by Git LFS to use Would that approach suffice for your use case? |
Hey Chris, thank you for looking into this. Going by git-config definition for So either
Personally I prefer option 2 but my experience with LFS is limited and not sure if there are unexpected effects in doing so. I also do not recommend doing the URL substitution more than once, that is guaranteed to break some of the setups out there, which match other rules after substitution. What I think may work, is to change the order of operations in Best regards, |
Thanks for the thoughtful reply! May I ask, just for context, if you're able to use
That's what I was considering too, but I confess I'm concerned there may be other edge cases which have to be considered where a change would break existing users' configurations. (We'll also have to handle adding and removing trailing I think what I'll do is mark this as an enhancement for the next major release, where we can break backwards compatibility with the behaviour of prior releases. In the meantime, though, I'll add something to our documentation to clarify that at present we append the |
The current work-around which we're using is to have a repo root .lfsconfig with the original pre-substitution LFS URL, which then goes cleanly thru substitutions as expected, being fully defined and not derrived.
While it may seem redundant - after all this URL is also auto-derrived inside git-lfs - the fact this is present in the .lfsconfig makes it go thru substitutions and matches successfully. I believe this is better since it allows us to change URLs for all repos from a single central place, the global .gitconfig. This is an AOSP build, in case you're wondering, so hundreds and hundreds of git repos. I also tested the I do understand what you say about side effects - this is the kind of change that's really hard to unit test 100% of in-the-wild cases. So seems appropriate for next major release, in the mean time if you can update git-lfs documentation to reflect this corner-case, maybe it would save some soul a day or 2 of debugging. Thanks again for looking at this and for all your work here! |
I'm working on some documentation updates, first of all, and thank you for the additional context regarding your use case. If I understand correctly, you'd like to specify a placeholder Git LFS server URL in each repository's I thought I should ask if you've tried using the So for instance, if I put the following into
and this into a Git configuration file like
then the Git LFS server URL is constructed as
In other words, I don't think you need to set |
Our Server Discovery documentation describes how we form Git LFS server API endpoint URLs based on Git remotes and other Git and Git LFS configurations. This documentation was introduced in commit 21e1695 of PR git-lfs#1641 and has only been lightly modified since then. As discusssed in issue git-lfs#5528, we append "/info/lfs" to Git remote URLs, but only after rewriting those URLs according to any "url.{name}.insteadOf" configurations, which is somewhat counter to what is implied by Git's own documentation of these settings. We may change this behaviour in a future Git LFS major release. For the present, though, we simply add a fuller description of how we convert Git remote URLs into Git LFS API server URLs to our documentation, specifically touching on the sequence in which we rewrite, convert, and append the "/info/lfs" path segments to the remote URLs. In PR git-lfs#3748 we added support for Git LFS endpoints defined by "file://" URLs, and in PR git-lfs#3918 we enhanced this by also accepting local file paths in remote URLs, so we also include comments on how we handle these cases in our new documentation. Further, although support for distinct URLs used only for upload operations has existed since PR git-lfs#949, it is not mentioned in our Server Discovery documentation, so we add notes on this feature now as well. 4469 - default remotes (lfsdefault, lfspushdefault) 5066 - autodetect, searchall
Describe the bug
If one does not define lfs.url, git-lfs falls back to trying a URL based on the local clone. That is as designed and documented.
However, the URL substitution using insteadOf only applies to clone URL, not to the generated derrived URL.
To Reproduce
Expected behavior
When doing git-lfs pull, it replaces https://originalserver/reponame.git/info/lfs URL with https://newserver/reponame.git/info/lfs and connects to the newserver instead.
System environment
Linux Fedora
Output of
git lfs env
Additional context
This happens during LFS URL being initialized from clone URL here.
NewEndpoint runs the URL alias replace here, on the git clone remote URL. In our example, that URL is https://originalserver/reponame
After the git clone remote URL is (unsuccessfully) aliased, NewEndpointFromCloneURL() appends '/info/lfs' and concludes.
The above has been confirmed via println on a local git-lfs source copy and build.
Ideally we want to first append the /info/lfs part, building the full URL from the clone URL, before puttint it thru aliasing engine.
The text was updated successfully, but these errors were encountered: