-
Notifications
You must be signed in to change notification settings - Fork 321
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
Fix resetting a Git working tree to the latest revision of a branch #8170
Conversation
Signed-off-by: Sebastian Schuberth <[email protected]>
Signed-off-by: Sebastian Schuberth <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8170 +/- ##
=========================================
Coverage 67.16% 67.16%
Complexity 2052 2052
=========================================
Files 358 358
Lines 17166 17166
Branches 2462 2462
=========================================
Hits 11530 11530
Misses 4613 4613
Partials 1023 1023
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
b2262a1
to
40f2149
Compare
The `.git/FETCH_HEAD` file does not only contain a single ref for the current branch, but all refs that have been fetched last. Do not assume the entry for the current branch to be the first one, and use JGit's `FetchResult` to search for the correct resolved revision to reset to. Fixes #7725. Signed-off-by: Sebastian Schuberth <[email protected]>
40f2149
to
4a0e912
Compare
@@ -230,19 +233,41 @@ class Git : VersionControlSystem(), CommandLineTool { | |||
} else { | |||
workingTree.runGit("fetch", "--tags", "origin") | |||
} |
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.
commit-msg: Would it make sense to link 1 (I assume this commit introduced the bug) ?
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 assume this commit introduced the bug
I'm actually not sure how guilty that commit really is. So far, running git reset --hard FETCH_HEAD
in this scenario has always worked for me, and also @nnobelis was only able to reproduce this with a single of the hundreds repos they're scanning. So I assume this rather to be a Git server implementation bug, but it could be a JGit bug as well... I simply could not find any specs on the ordering of advertised refs.
So that's why I didn't explicitly refer to that commit, as I'm still unsure where the bug lies.
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.
Makes sense, thanks for explaining!
Please have a look at the individual commit messages for the details.