Skip to content
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

Merged
merged 3 commits into from
Jan 25, 2024

Conversation

sschuberth
Copy link
Member

Please have a look at the individual commit messages for the details.

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (360dbe1) 67.16% compared to head (4a0e912) 67.16%.
Report is 2 commits behind head on main.

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           
Flag Coverage Δ
funTest-docker 66.25% <ø> (ø)
test 37.01% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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]>
@@ -230,19 +233,41 @@ class Git : VersionControlSystem(), CommandLineTool {
} else {
workingTree.runGit("fetch", "--tags", "origin")
}
Copy link
Member

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) ?

Copy link
Member Author

@sschuberth sschuberth Jan 25, 2024

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.

Copy link
Member

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!

@sschuberth sschuberth merged commit 8472931 into main Jan 25, 2024
21 of 22 checks passed
@sschuberth sschuberth deleted the fix-git-fetch-head branch January 25, 2024 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants