| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Test for edge cases and error conditions in git diff processing |
| 4 |
|
| 5 |
. ${top_srcdir-.}/tests/common.sh |
| 6 |
|
| 7 |
# Test 1: Mode-only change (GIT_DIFF_MODE_ONLY) |
| 8 |
cat << 'EOF' > git-mode-only.patch |
| 9 |
diff --git a/script.sh b/script.sh |
| 10 |
old mode 100644 |
| 11 |
new mode 100755 |
| 12 |
index abc123..abc123 100644 |
| 13 |
EOF |
| 14 |
|
| 15 |
# Test 2: Git diff with no hunks and binary marker |
| 16 |
cat << 'EOF' > git-binary-no-hunks.patch |
| 17 |
diff --git a/image.png b/image.png |
| 18 |
new file mode 100644 |
| 19 |
index 0000000..abc123 |
| 20 |
Binary files /dev/null and b/image.png differ |
| 21 |
EOF |
| 22 |
|
| 23 |
# Test 3: Copy operation (not pure rename) |
| 24 |
cat << 'EOF' > git-copy.patch |
| 25 |
diff --git a/original.txt b/copy.txt |
| 26 |
similarity index 85% |
| 27 |
copy from original.txt |
| 28 |
copy to copy.txt |
| 29 |
index abc123..def456 100644 |
| 30 |
--- a/original.txt |
| 31 |
+++ b/copy.txt |
| 32 |
@@ -1,3 +1,4 @@ |
| 33 |
line 1 |
| 34 |
line 2 |
| 35 |
line 3 |
| 36 |
+added line |
| 37 |
EOF |
| 38 |
|
| 39 |
# Test 4: Malformed git headers (should fall back gracefully) |
| 40 |
cat << 'EOF' > malformed-git.patch |
| 41 |
diff --git incomplete |
| 42 |
some random content |
| 43 |
--- a/file.txt |
| 44 |
+++ b/file.txt |
| 45 |
@@ -1 +1 @@ |
| 46 |
-old |
| 47 |
+new |
| 48 |
EOF |
| 49 |
|
| 50 |
# Test 5: Git diff with both old and new mode changes |
| 51 |
cat << 'EOF' > git-mode-and-content.patch |
| 52 |
diff --git a/file.txt b/file.txt |
| 53 |
old mode 100644 |
| 54 |
new mode 100755 |
| 55 |
index abc123..def456 |
| 56 |
--- a/file.txt |
| 57 |
+++ b/file.txt |
| 58 |
@@ -1 +1,2 @@ |
| 59 |
content |
| 60 |
+new line |
| 61 |
EOF |
| 62 |
|
| 63 |
# Test 6: Empty git diff (no changes) |
| 64 |
cat << 'EOF' > git-empty.patch |
| 65 |
diff --git a/unchanged.txt b/unchanged.txt |
| 66 |
index abc123..abc123 100644 |
| 67 |
EOF |
| 68 |
|
| 69 |
echo "=== Test 1: Mode-only change ===" |
| 70 |
${LSDIFF} --git-extended-diffs=include -s git-mode-only.patch 2>errors1 >result1 || exit 1 |
| 71 |
[ -s errors1 ] && exit 1 |
| 72 |
|
| 73 |
cat << EOF | cmp - result1 || exit 1 |
| 74 |
! a/script.sh |
| 75 |
EOF |
| 76 |
|
| 77 |
echo "=== Test 2: Binary file with no hunks ===" |
| 78 |
${LSDIFF} --git-extended-diffs=include -s git-binary-no-hunks.patch 2>errors2 >result2 || exit 1 |
| 79 |
[ -s errors2 ] && exit 1 |
| 80 |
|
| 81 |
cat << EOF | cmp - result2 || exit 1 |
| 82 |
+ a/image.png |
| 83 |
EOF |
| 84 |
|
| 85 |
echo "=== Test 3: Copy operation ===" |
| 86 |
${LSDIFF} --git-extended-diffs=include -s git-copy.patch 2>errors3 >result3 || exit 1 |
| 87 |
[ -s errors3 ] && exit 1 |
| 88 |
|
| 89 |
cat << EOF | cmp - result3 || exit 1 |
| 90 |
! b/copy.txt |
| 91 |
EOF |
| 92 |
|
| 93 |
echo "=== Test 4: filterdiff with copy operation ===" |
| 94 |
${FILTERDIFF} --git-extended-diffs=include -i "*/copy*" git-copy.patch 2>errors4 >result4 || exit 1 |
| 95 |
[ -s errors4 ] && exit 1 |
| 96 |
|
| 97 |
cat << 'EOF' | cmp - result4 || exit 1 |
| 98 |
diff --git a/original.txt b/copy.txt |
| 99 |
similarity index 85% |
| 100 |
copy from original.txt |
| 101 |
copy to copy.txt |
| 102 |
index abc123..def456 100644 |
| 103 |
--- a/original.txt |
| 104 |
+++ b/copy.txt |
| 105 |
@@ -1,3 +1,4 @@ |
| 106 |
line 1 |
| 107 |
line 2 |
| 108 |
line 3 |
| 109 |
+added line |
| 110 |
EOF |
| 111 |
|
| 112 |
echo "=== Test 5: filterdiff with copy by target name ===" |
| 113 |
${FILTERDIFF} --git-extended-diffs=include -i "*/copy*" git-copy.patch 2>errors5 >result5 || exit 1 |
| 114 |
[ -s errors5 ] && exit 1 |
| 115 |
|
| 116 |
# Should still match (uses best_name) |
| 117 |
cat << 'EOF' | cmp - result5 || exit 1 |
| 118 |
diff --git a/original.txt b/copy.txt |
| 119 |
similarity index 85% |
| 120 |
copy from original.txt |
| 121 |
copy to copy.txt |
| 122 |
index abc123..def456 100644 |
| 123 |
--- a/original.txt |
| 124 |
+++ b/copy.txt |
| 125 |
@@ -1,3 +1,4 @@ |
| 126 |
line 1 |
| 127 |
line 2 |
| 128 |
line 3 |
| 129 |
+added line |
| 130 |
EOF |
| 131 |
|
| 132 |
echo "=== Test 6: Malformed git headers fallback ===" |
| 133 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include malformed-git.patch 2>errors6 >result6 || exit 1 |
| 134 |
[ -s errors6 ] && exit 1 |
| 135 |
|
| 136 |
cat << EOF | cmp - result6 || exit 1 |
| 137 |
a/file.txt |
| 138 |
EOF |
| 139 |
|
| 140 |
echo "=== Test 7: Mode and content change ===" |
| 141 |
${LSDIFF} --git-extended-diffs=include -s git-mode-and-content.patch 2>errors7 >result7 || exit 1 |
| 142 |
[ -s errors7 ] && exit 1 |
| 143 |
|
| 144 |
cat << EOF | cmp - result7 || exit 1 |
| 145 |
! a/file.txt |
| 146 |
EOF |
| 147 |
|
| 148 |
echo "=== Test 8: Empty git diff ===" |
| 149 |
${LSDIFF} --git-extended-diffs=include -s git-empty.patch 2>errors8 >result8 || exit 1 |
| 150 |
[ -s errors8 ] && exit 1 |
| 151 |
|
| 152 |
# Empty git diff should produce no output |
| 153 |
[ -s result8 ] && exit 1 |
| 154 |
|
| 155 |
echo "=== Test 9: filterdiff with git-prefixes on various types ===" |
| 156 |
${FILTERDIFF} --git-extended-diffs=include --git-prefixes=strip -i "*.sh" git-mode-only.patch 2>errors9 >result9 || exit 1 |
| 157 |
[ -s errors9 ] && exit 1 |
| 158 |
|
| 159 |
cat << 'EOF' | cmp - result9 || exit 1 |
| 160 |
diff --git a/script.sh b/script.sh |
| 161 |
old mode 100644 |
| 162 |
new mode 100755 |
| 163 |
index abc123..abc123 100644 |
| 164 |
EOF |
| 165 |
|
| 166 |
echo "=== Test 10: Test include/exclude with no matches ===" |
| 167 |
${FILTERDIFF} --git-extended-diffs=include -i "nonexistent*" git-mode-only.patch 2>errors10 >result10 || exit 1 |
| 168 |
[ -s errors10 ] && exit 1 |
| 169 |
|
| 170 |
# Should be empty |
| 171 |
[ -s result10 ] && exit 1 |
| 172 |
|
| 173 |
echo "=== Test 11: Multiple git diff types in one patch ===" |
| 174 |
cat << 'EOF' > mixed-git-types.patch |
| 175 |
diff --git a/deleted.txt b/deleted.txt |
| 176 |
deleted file mode 100644 |
| 177 |
index abc123..0000000 |
| 178 |
--- a/deleted.txt |
| 179 |
+++ /dev/null |
| 180 |
@@ -1 +0,0 @@ |
| 181 |
-content |
| 182 |
diff --git a/old.txt b/new.txt |
| 183 |
similarity index 100% |
| 184 |
rename from old.txt |
| 185 |
rename to new.txt |
| 186 |
diff --git a/script.sh b/script.sh |
| 187 |
old mode 100644 |
| 188 |
new mode 100755 |
| 189 |
index def456..def456 100644 |
| 190 |
EOF |
| 191 |
|
| 192 |
${LSDIFF} --git-extended-diffs=include -s mixed-git-types.patch 2>errors11 >result11 || exit 1 |
| 193 |
[ -s errors11 ] && exit 1 |
| 194 |
|
| 195 |
cat << EOF | cmp - result11 || exit 1 |
| 196 |
- a/deleted.txt |
| 197 |
! a/old.txt |
| 198 |
! a/script.sh |
| 199 |
EOF |
| 200 |
|
| 201 |
echo "=== Test 12: filterdiff with pattern matching mixed types ===" |
| 202 |
${FILTERDIFF} --git-extended-diffs=include -i "a/*.txt" mixed-git-types.patch 2>errors12 >result12 || exit 1 |
| 203 |
[ -s errors12 ] && exit 1 |
| 204 |
|
| 205 |
cat << 'EOF' | cmp - result12 || exit 1 |
| 206 |
diff --git a/deleted.txt b/deleted.txt |
| 207 |
deleted file mode 100644 |
| 208 |
index abc123..0000000 |
| 209 |
--- a/deleted.txt |
| 210 |
+++ /dev/null |
| 211 |
@@ -1 +0,0 @@ |
| 212 |
-content |
| 213 |
diff --git a/old.txt b/new.txt |
| 214 |
similarity index 100% |
| 215 |
rename from old.txt |
| 216 |
rename to new.txt |
| 217 |
EOF |
| 218 |
|
| 219 |
echo "All edge case tests passed!" |
| 220 |
exit 0 |