diff --git a/lib/git_diff_parser/patch.rb b/lib/git_diff_parser/patch.rb index d0a7ed4..8fa5d70 100644 --- a/lib/git_diff_parser/patch.rb +++ b/lib/git_diff_parser/patch.rb @@ -1,7 +1,7 @@ module GitDiffParser # Parsed patch class Patch - RANGE_INFORMATION_LINE = /^@@ .+\+(?\d+),/ + RANGE_INFORMATION_LINE = /^@@ -(?\d+),.+\+(?\d+),/ MODIFIED_LINE = /^\+(?!\+|\+)/ REMOVED_LINE = /^[-]/ NOT_REMOVED_LINE = /^[^-]/ @@ -84,7 +84,7 @@ def removed_lines lines.each_with_index.inject([]) do |lines, (content, patch_position)| case content when RANGE_INFORMATION_LINE - line_number = Regexp.last_match[:line_number].to_i + line_number = Regexp.last_match[:old_line_number].to_i when REMOVED_LINE line = Line.new( content: content, @@ -93,6 +93,8 @@ def removed_lines ) lines << line line_number += 1 + when NOT_REMOVED_LINE + line_number += 1 end lines diff --git a/spec/git_diff_parser/patch_spec.rb b/spec/git_diff_parser/patch_spec.rb index eb5de2c..b3769ce 100644 --- a/spec/git_diff_parser/patch_spec.rb +++ b/spec/git_diff_parser/patch_spec.rb @@ -27,7 +27,7 @@ module GitDiffParser patch = Patch.new(patch_body) expect(patch.removed_lines.size).to eq(7) - expect(patch.removed_lines.map(&:number)).to eq [11, 36, 37, 38, 39, 40, 48] + expect(patch.removed_lines.map(&:number)).to eq [14, 38, 39, 40, 41, 42, 58] expect(patch.removed_lines.map(&:patch_position)).to eq [4, 21, 22, 23, 24, 25, 36] end