Reimplements the Git merge conflict resolution #5046
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's the problem this PR addresses?
The current merge conflict resolution algorithm is nice because it operates using only the conflict markers that Git puts into the files, but it has several drawbacks:
Git sometimes generates bogus conflict markers, which lead to the resulting lockfile to have invalid checksums ([Bug] Automerge confused by change of checksums between yarn versions #2583, [Bug] yarn failed to handle merged yarn.lock with duplicated key #1771 (comment), ...)
Git doesn't put conflict markers on the
__metadata.version
field (because it rarely change except when you upgrade Yarn, so there are no conflicts), which prevents us from knowing whether the merged lockfile has accurate metadata.Closes #2583
Closes #5041
How did you fix it?
This diff reimplements the merge conflict auto-resolver to instead query the Git state. It retrieves the original variants of the lockfile, ignores the ones that don't make sense, tries to perform a couple of compatibility fixes if it knows how (useful for the lockfile v6 -> v7 migration), and merges the resulting data.
The main drawback is that the
yarn install
command must be run within the context of the conflictinggit merge
command. You cannot anymore accidentally commit the conflict, and fix it later (because then we'd lose the information telling us which commits are being merged).Checklist