Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/git_diff_parser/patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Patch
RANGE_INFORMATION_LINE = /^@@ .+\+(?<line_number>\d+),/
MODIFIED_LINE = /^\+(?!\+|\+)/
NOT_REMOVED_LINE = /^[^-]/
NO_NEWLINE_MESSAGE = /^\\ No newline at end of file$/

attr_accessor :file, :body, :secure_hash
# @!attribute [rw] file
Expand Down Expand Up @@ -60,6 +61,8 @@ def changed_lines
case content
when RANGE_INFORMATION_LINE
line_number = Regexp.last_match[:line_number].to_i
when NO_NEWLINE_MESSAGE
# nop
when MODIFIED_LINE
line = Line.new(
content: content,
Expand Down
11 changes: 11 additions & 0 deletions spec/git_diff_parser/patch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ module GitDiffParser
end
end

context "Newline inserted at EOF" do
describe "changed_line_numbers" do
it "returns changed line number" do
patch_body = File.read('spec/support/fixtures/file4.diff')
patch = Patch.new(patch_body)

expect(patch.changed_line_numbers).to eq [4]
end
end
end

describe '#find_patch_position_by_line_number' do
it 'returns patch position that were included' do
patch_body = File.read('spec/support/fixtures/patch.diff')
Expand Down
7 changes: 7 additions & 0 deletions spec/support/fixtures/file4.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@@ -1,4 +1,4 @@
1
2
3
-File1
\ No newline at end of file
+File1 v2