You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * @param contextSize * How many lines of context around each changed line should be included.*/classDiffFactory(privatevalcontextSize:Int) {
companionobject {
privateconstvalLINE_SEPARATOR="\n"
}
/** * Creates a git-apply compatible diff.*/funcomputeDiff(
filename:String,
originalContent:String,
newContent:String
): String=UnifiedDiffUtils.generateUnifiedDiff(
"a/$filename", // a/ and b/ required for git-apply compatibility"b/$filename",
originalContent.split(LINE_SEPARATOR),
DiffUtils.diff(
originalContent, newContent,
NullDiffAlgorithmListener
),
contextSize
).joinToString(LINE_SEPARATOR)
}
With contextSize = 3 the following diff gets created:
(important: line with 1 space at the end - I've also added an empty newline to support git apply call from file instead of system in)
5. git apply fails
> git apply example.diff
error: patch failed: examples/unchain-variable-declaration.js:1
error: examples/unchain-variable-declaration.js: patch does not apply
Expected behavior
Git apply works with the following patch:
Describe the bug
Diff cannot be applied with
git apply
To Reproduce
contextSize = 3
the following diff gets created:(important: line with 1 space at the end - I've also added an empty newline to support git apply call from file instead of system in)
5.
git apply
failsExpected behavior
Git apply works with the following patch:
The difference is that the index is limited to 1,4 (original input is 4 lines long).
System
The text was updated successfully, but these errors were encountered: