| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# This is a rediff(1) testcase. |
| 4 |
# Test: rediff should handle empty hunks properly |
| 5 |
# |
| 6 |
# Bug report: When a hunk becomes empty after manual editing (i.e., all the |
| 7 |
# +/- lines are removed leaving only context lines), rediff produces malformed |
| 8 |
# output with very large numbers in the hunk header. This causes "corrupt patch" |
| 9 |
# errors when trying to apply the resulting patch with git apply or patch. |
| 10 |
# |
| 11 |
# The bug manifests as hunk headers like: |
| 12 |
# @@ -13,0 +13,18446744073709551615 @@ |
| 13 |
# instead of either removing the empty hunk entirely or producing a valid header. |
| 14 |
# |
| 15 |
# This test case reproduces the issue by: |
| 16 |
# 1. Creating an original patch with 2 hunks |
| 17 |
# 2. Creating a modified version where the second hunk has no +/- lines (empty) |
| 18 |
# 3. Running rediff and checking for the malformed output |
| 19 |
# |
| 20 |
# Expected behavior: rediff should either remove empty hunks or handle them |
| 21 |
# gracefully without producing malformed hunk headers. |
| 22 |
|
| 23 |
. ${top_srcdir-.}/tests/common.sh |
| 24 |
|
| 25 |
# Create original patch with 2 hunks |
| 26 |
cat << "EOF" > original.patch |
| 27 |
--- hello |
| 28 |
+++ hello |
| 29 |
@@ -10,7 +10,7 @@ |
| 30 |
8 |
| 31 |
9 |
| 32 |
10 |
| 33 |
-12 |
| 34 |
+12a |
| 35 |
13 |
| 36 |
14 |
| 37 |
15 |
| 38 |
@@ -13,6 +13,7 @@ |
| 39 |
11 |
| 40 |
12a |
| 41 |
13 |
| 42 |
+b |
| 43 |
14 |
| 44 |
15 |
| 45 |
16 |
| 46 |
EOF |
| 47 |
|
| 48 |
# Create modified version where second hunk is empty (no +/- lines, only context) |
| 49 |
cat << "EOF" > modified.patch |
| 50 |
--- hello |
| 51 |
+++ hello |
| 52 |
@@ -10,7 +10,7 @@ |
| 53 |
8 |
| 54 |
9 |
| 55 |
10 |
| 56 |
-12 |
| 57 |
+12a |
| 58 |
13 |
| 59 |
14 |
| 60 |
15 |
| 61 |
@@ -13,6 +13,6 @@ |
| 62 |
11 |
| 63 |
12a |
| 64 |
13 |
| 65 |
14 |
| 66 |
15 |
| 67 |
16 |
| 68 |
EOF |
| 69 |
|
| 70 |
# Run rediff - this should handle empty hunks properly |
| 71 |
${REDIFF} original.patch modified.patch > result.patch || exit 1 |
| 72 |
|
| 73 |
# The expected correct behavior would be to either: |
| 74 |
# 1. Remove the empty hunk entirely (leaving only 1 hunk) |
| 75 |
# 2. Handle it gracefully without malformed headers |
| 76 |
# |
| 77 |
# Currently this produces malformed output with very large numbers |
| 78 |
# in hunk headers, which is the bug being tested. |
| 79 |
|
| 80 |
# Verify the result has proper patch format |
| 81 |
hunk_count=$(grep -c '^@@' result.patch) |
| 82 |
if [ "$hunk_count" -eq 0 ]; then |
| 83 |
echo "ERROR: No hunks found in result" |
| 84 |
exit 1 |
| 85 |
fi |
| 86 |
|
| 87 |
# Check if the result can be applied to verify it's not corrupt |
| 88 |
seq 100 > hello |
| 89 |
if ! ${PATCH} hello < result.patch; then |
| 90 |
echo "ERROR: Result patch cannot be applied (corrupt patch)" |
| 91 |
exit 1 |
| 92 |
fi |
| 93 |
|
| 94 |
echo "Test completed successfully" |