Skip to content

Incorrect line number for hunk adding one line only #12

@NickAb

Description

@NickAb
require 'git_diff'

patch = "diff --git a/file b/file\nindex 96e92a720b..ffd93b8533 100644\n--- a/file\n+++ b/file\n@@ -15,0 +16 @@\n+  asdasd\n"
diff = GitDiff.from_string(patch)

diff.files[0].hunks[0].range_info.new_range

expected:

=> #<GitDiff::LineNumberRange:... @number_of_lines=1, @start=16>

actual:

=> #<GitDiff::LineNumberRange:... @number_of_lines=0, @start=16>

Hunk header might omit , and following size of a hunk in a case when only one line was added, for example:

@@ -15,0 +16 @@

which is equal to:

@@ -15,0 +16,1 @@

https://github.com/anolson/git_diff/blob/master/lib/git_diff/line_number_range.rb#L9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions