-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hunk/ldiff unified diff against empty files
The ldiff bin (and it's underlying implementation) behaves weirdly when given an empty file as one of its operand (old or new file). This is particularly painful when doing diff for new or deleted files, especially as one could think it is a simple case as the whole content should be considered either added or removed. To demonstrate the issue, I'm adding test cases to demonstrate how ldiff behaves when a 4-lines file is compared to empty, using all supported formats and in both directions. The expected result has been collected using GNU diff 3.10.
- Loading branch information
Showing
14 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
0a1,4 | ||
> one | ||
> two | ||
> three | ||
> four |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*** spec/fixtures/empty 2025-01-31 12:14:52.856031635 +0100 | ||
--- spec/fixtures/four_lines 2025-01-31 12:13:45.476036544 +0100 | ||
*************** | ||
*** 0 **** | ||
--- 1,4 ---- | ||
+ one | ||
+ two | ||
+ three | ||
+ four |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
0a | ||
one | ||
two | ||
three | ||
four | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
a0 | ||
one | ||
two | ||
three | ||
four | ||
. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- spec/fixtures/empty 2025-01-31 12:14:52.856031635 +0100 | ||
+++ spec/fixtures/four_lines 2025-01-31 12:13:45.476036544 +0100 | ||
@@ -0,0 +1,4 @@ | ||
+one | ||
+two | ||
+three | ||
+four |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
1,4d0 | ||
< one | ||
< two | ||
< three | ||
< four |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*** spec/fixtures/four_lines 2025-01-31 12:13:45.476036544 +0100 | ||
--- spec/fixtures/empty 2025-01-31 12:14:52.856031635 +0100 | ||
*************** | ||
*** 1,4 **** | ||
- one | ||
- two | ||
- three | ||
- four | ||
--- 0 ---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1,4d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
d1 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- spec/fixtures/four_lines 2025-01-31 12:13:45.476036544 +0100 | ||
+++ spec/fixtures/empty 2025-01-31 12:14:52.856031635 +0100 | ||
@@ -1,4 +0,0 @@ | ||
-one | ||
-two | ||
-three | ||
-four |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters