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
Resolve reference for remote git repositories (makes fetchGit work with non-'master' branch) #4638
Conversation
e131691
to
bc4e125
Compare
Update: I've rebased the pull request and added a more explicit test in tests/fetchGit.sh. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
What is needed to get this PR merged ? I'm quite interested in this functionality since it can cause some confusion for Nix newcomers that create projects through GitHub or GitLab. |
@minijackson If someone is willing to review this, I can make the necessary changes (if any) to bring the patches up to date. I haven't heard anything so far. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff! In my opinion, only the first comment about the --symref
option is important, the rest are just minor comments.
src/libfetchers/git.cc
Outdated
{ | ||
// Append something in front of the url to prevent collision with the | ||
// cached repo. | ||
Path cachePath = getCacheDir() + "/nix/gitv3/" + hashString(htSHA256, "<ref>|" + actualUrl).to_string(Base32, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be factorized with the similar line in fetch
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm not mistaken, it is possible to get the remote HEAD
by reading the HEAD
file in the cached repository. Is it possible to do it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a helper function for cache path.
HEAD
is not currently updated in the cached repo (it is initialized to __nix_dummy_branch
). I think we could use it instead of the cache file since it's not used for any other purpose, but it seems more straightforward to just write it to a separate file. Let me know if you still prefer using HEAD
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally think that one cache dir is easier to maintain than two, but I do not feel that strongly about it. If you feel this is more straightforward, I won't bother you ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a side note the getCachePath
function can also be used on line 418 of git.cc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the pull request to maintain a single git repo as the cache, and storing the HEAD as a symbolic ref within the cache. This complicated the logic in fetch()
slightly, so I also added a commit with some refactoring which I think makes this easier to understand overall.
6926bea
to
1467741
Compare
Built it with |
99fabc9
to
375c48d
Compare
Thank you for the review and additional testing, @minijackson. |
Added another commit to update the documentation to account for these changes, and explains how local repositories are handled. Fixes #5900. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
All tests pass on my end.
Hi @edolstra. I think this pull request is in a good state and there seems to be some interest in this feature. Could you take a look? |
Would be good to see this PR land and #5139 resolved :) I ran into this issue while trying to introduce nix flake into a codebase but it choked on fetching a git repository that defaults to |
Needs a rebase. |
375c48d
to
1979834
Compare
@bjornfor Thanks, I have rebased and update the pull request. Please take a look. |
@orbekk: Sorry, I was just pointing out that the PR needed a rebase. I don't have commit access nor feel qualified to review. |
Hi @thufschmitt, could you help me find a reviewer? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @thufschmitt, could you help me find a reviewer?
I guess I just did that 😛
Looks good overall, just a couple of small suggestions
Resolves the HEAD reference from the remote repository instead of assuming "master".
Extract the handling of a local dirty workdir to a helper function.
The previous head caching implementation stored two paths in the local cache; one for the cached git repo and another textfile containing the resolved HEAD ref. This commit instead stores the resolved HEAD by setting the HEAD ref in the local cache appropriately.
Update the documentation about how `ref` is resolved if it is not specified. Add a note about special handling of local workdirs with `git+file`.
These utility functions can be shared between the git and github fetchers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good :)
I’ll leave it for a couple days in case @edolstra wants to have another look since he’s the author of that part of the code, and I’ll merge it if nothing comes before that
Thanks! |
Thanks for the review @thufschmitt |
NixOS#6290 introduced a regex pattern to account for tags when resolving sourcehut refs. NixOS#4638 reafactored the code, accidentally treating the pattern as a regular string, causing all non-HEAD ref resolving to break. This fixes the regression and adds more test cases to avoid future breakage.
#6290 introduced a regex pattern to account for tags when resolving sourcehut refs. #4638 reafactored the code, accidentally treating the pattern as a regular string, causing all non-HEAD ref resolving to break. This fixes the regression and adds more test cases to avoid future breakage. (cherry picked from commit 9f6b463)
Resolves the HEAD reference from the remote repository instead of assuming "master".
For remote repositories, the HEAD ref is cached with the same cache policy as the local cached repo.
Fixes #4456.