Skip to content

Unexpected new line in a unidiff hunk #21

Description

@krlvi

Hello! Firstly, let me say thank you for creating this library - it is something that I get to enjoy using indirectly through gitoxide

I think we've run into a condition which might generate hunks incorrectly, or at the very least, differently from how git diff produces them.

The problematic change takes the following form:

Before

a

foo

b

After

a

b

The unidiff I'd expect is

@@ -1,5 +1,3 @@
 a

-foo
-
 b

However the unidiff I get from imara-diff looks like

@@ -1,5 +1,3 @@
 a
-
-foo

 b

I need to clarify that this only happens when there are other changes preceding it - if there are no other changes, the unidiff looks as expected (aligned with git's diff output).

In order to make debugging easier, I created a test with the scenario that allowed me to reproduce this - https://github.com/krlvi/imara-diff/blob/f259243ba3873189744b81b7a8d7e0dde58b0700/src/tests.rs#L159

Attaching below a screenshot from the test output (I allowed myself to add pretty_assertions to my branch for better visibility)
Image

Thanks

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