-
Notifications
You must be signed in to change notification settings - Fork 15
Fix how line numbers are counted in Patch#removed_lines #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
module GitDiffParser | ||
# Parsed patch | ||
class Patch | ||
RANGE_INFORMATION_LINE = /^@@ .+\+(?<line_number>\d+),/ | ||
RANGE_INFORMATION_LINE = /^@@ -(?<old_line_number>\d+),.+\+(?<line_number>\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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could be wrong, but I think we should only be incrementing Here is a fix and a failing test: cjoudrey@a37ad98#diff-5167fa12a2c6d40aaa8884e40efa7ac4 Explanation: Original file: type Query {
a: String
b: String
c: String
} Patch: @@ -1,5 +1,5 @@
type Query {
+ d: String
a: String
b: String
- c: String
} The number of the line being removed here is number With this current pull request, the number is |
||
line_number += 1 | ||
end | ||
|
||
lines | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I can, tell
,\d+
should be optional.For example:
I believe we can change this line to:
I wrote a failing test and fix here: cjoudrey@858a945