-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Respect the force flag on refspecs in git_remote_fetch #5854
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
Respect the force flag on refspecs in git_remote_fetch #5854
Conversation
@carlosmn any chance you can spare some 👀 for this? Your knowledge of the networking code is far superior to mine. |
Oops I guess we've been behaving like everything is forced forever. I let the tests run and it looks like there's memory errors here where one of the variables isn't initialized. Running it locally it keeps failing at
While the overall approach seems like it should work, there do seem to be some issues in the code that can be caught by the tests. |
I suspect the error happens in the case where we first create the remote-tracking branch so we look it up but |
I notice that the test I wrote is also failing
This is strange as it passes on my machine. It looks like it's failing to clean up after the first test and so the test repo is in an unexpected state. Am I missing something on the cleanup? |
It is most likely something to do with cleanup or the interaction between tests. Running just that failing test does pass. |
When you create the new root commit the second time around, the branch has commits, so the empty parent list means a zero-commit as first parent, whereas the existing tip of the branch is whatever actual commit you created. |
This might be the result of #5842 which is somewhat recent and might explain why you don't see it yourself if you branched off of something earlier. |
Ah interseting, I've rebased off |
4e7d891
to
68aec6e
Compare
I had to expose a |
Hey peeps, any chance someone could re-run the tests for this? |
Exposing internal clar functionality is not the way to go. Check out how other tests, e.g. the Lines 6 to 22 in 868f4bc
|
68aec6e
to
1713ab4
Compare
Thanks for the hint! I've reworked this to use |
Hey folks, sorry to bother, any chance someone can run the tests again? |
Sure, CI has been kicked into action. |
I managed to reproduce the memory sanitizer failure in a local version of the CI pipeline and I've fixed the failure there. This should be good to go now. |
Could someone nudge CI into action again? |
Looks like all the tests are passing, is there anything else to do to merge this? |
@carlosmn is this looking good? |
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.
The code itself seems fine, mostly just the tests should be closer to the patterns and utilities that we already use elsewhere.
The test functions themselves could be made smaller and the "time-traveling fetch" function could also perform the check but that's minor.
tests/remote/fetch.c
Outdated
strncpy(result, path, strlen(path)); | ||
return result; | ||
} | ||
} |
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.
This function seems unused.
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.
🤦 removed
tests/remote/fetch.c
Outdated
|
||
cl_git_pass(git_buf_join(&repo1_path_buf, '/', sandbox, "fetchtest_repo1")); | ||
repo1_path = calloc(repo1_path_buf.size, sizeof(char)); | ||
git_buf_copy_cstr(repo1_path, repo1_path_buf.size, &repo1_path_buf); |
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.
This dance seems like it would be better by using git_buf_detach
.
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.
Done
tests/remote/fetch.c
Outdated
git_buf repo2_path_buf = GIT_BUF_INIT; | ||
const char *sandbox = clar_sandbox_path(); | ||
|
||
cl_git_pass(git_buf_join(&repo1_path_buf, '/', sandbox, "fetchtest_repo1")); |
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.
git_buf_joinpath
would be nicer here; it's what I was expecting and made me think you were trying to prepend slash :/
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.
Done
One bigger change and consequence of this is that the |
4226929
to
a569670
Compare
@carlosmn Thanks for the review, I believe I've addressed your comments. Regarding the larger change to |
Yes, that would require increasing the version of the remote callback structure and adding some sort of |
Fix fetching git repos after a force push. Users have been reporting that the index has not been updating for them. This was caused by the update to libgit2 1.3 (from 1.1) which has changed some behavior around force pushes. The index was squashed on 2021-09-24, and if a user had the index fetched from before that point, and they used nightly-2021-10-14 or newer, then the fetch would succeed, but the `refs/remotes/origin/HEAD` would not get updated. Cargo uses the `origin/HEAD` ref to know what to look at, and thus was looking at old data. The solution here is to use `+` on the refspec to force libgit2 to do a forced update (a fast-forward). I think this may have been introduced in libgit2 1.2 via libgit2/libgit2#5854, though that is just a guess. Fixes #9976
Fix fetching git repos after a force push. Users have been reporting that the index has not been updating for them. This was caused by the update to libgit2 1.3 (from 1.1) which has changed some behavior around force pushes. The index was squashed on 2021-09-24, and if a user had the index fetched from before that point, and they used nightly-2021-10-14 or newer, then the fetch would succeed, but the `refs/remotes/origin/HEAD` would not get updated. Cargo uses the `origin/HEAD` ref to know what to look at, and thus was looking at old data. The solution here is to use `+` on the refspec to force libgit2 to do a forced update (a fast-forward). I think this may have been introduced in libgit2 1.2 via libgit2/libgit2#5854, though that is just a guess. Fixes rust-lang#9976
This fixes #2957
If the
->force
flag on a refspec is not set then we check that the new refs are descendants of the current refs before updating them.