This has a side-effect that line numbers are shifted by +1 if the patch is near end of the file which does not have a trailing newline.
How to reproduce
If we have this unified diff:
diff --git a/file.txt b/file.txt
index 2ae21dc..0ce0636 100644
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1 @@
-First
\ No newline at end of file
+Second
And we inspect the changed_lines of this patch:
require "git_diff_parser"
output = File.open("file.diff").read
patches = GitDiffParser.parse(output)
puts patches[0].changed_lines.inspect
We will get this output
[#<GitDiffParser::Line:0x00005602fda5fd88 @number=2, @content="+Second\n", @patch_position=3>]
Expectation:
@number=1
Reality:
@number=2
This has a side-effect that line numbers are shifted by +1 if the patch is near end of the file which does not have a trailing newline.
How to reproduce
If we have this unified diff:
And we inspect the
changed_linesof this patch:We will get this output
Expectation:
@number=1Reality:
@number=2