| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Test complex mixed git diff scenarios |
| 4 |
# This test covers multiple git diff types in one patch file and edge cases |
| 5 |
|
| 6 |
. ${top_srcdir-.}/tests/common.sh |
| 7 |
|
| 8 |
# Create a complex patch with multiple git diff types: |
| 9 |
# 1. New file with content |
| 10 |
# 2. Deleted file |
| 11 |
# 3. Binary file |
| 12 |
# 4. Mode-only change |
| 13 |
# 5. Pure rename (100% similarity) |
| 14 |
# 6. Copy operation (< 100% similarity) |
| 15 |
# 7. Regular content change |
| 16 |
cat << EOF > complex-git.patch |
| 17 |
diff --git a/new-file.txt b/new-file.txt |
| 18 |
new file mode 100644 |
| 19 |
index 0000000..abcdef1 |
| 20 |
--- /dev/null |
| 21 |
+++ b/new-file.txt |
| 22 |
@@ -0,0 +1,2 @@ |
| 23 |
+This is a new file |
| 24 |
+with some content |
| 25 |
diff --git a/deleted-file.old b/deleted-file.old |
| 26 |
deleted file mode 100644 |
| 27 |
index fedcba9..0000000 |
| 28 |
--- a/deleted-file.old |
| 29 |
+++ /dev/null |
| 30 |
@@ -1,2 +0,0 @@ |
| 31 |
-This file will be deleted |
| 32 |
-goodbye |
| 33 |
diff --git a/binary-data.bin b/binary-data.bin |
| 34 |
new file mode 100644 |
| 35 |
index 0000000..1234567 |
| 36 |
Binary files /dev/null and b/binary-data.bin differ |
| 37 |
diff --git a/script-mode.sh b/script-mode.sh |
| 38 |
old mode 100644 |
| 39 |
new mode 100755 |
| 40 |
diff --git a/renamed-file.txt b/new-name.txt |
| 41 |
similarity index 100% |
| 42 |
rename from renamed-file.txt |
| 43 |
rename to new-name.txt |
| 44 |
diff --git a/copied-file.c b/copy-target.c |
| 45 |
similarity index 85% |
| 46 |
copy from copied-file.c |
| 47 |
copy to copy-target.c |
| 48 |
index abc123..def456 100644 |
| 49 |
--- a/copied-file.c |
| 50 |
+++ b/copy-target.c |
| 51 |
@@ -1,3 +1,4 @@ |
| 52 |
#include <stdio.h> |
| 53 |
int main() { |
| 54 |
+ printf("copied and modified\\n"); |
| 55 |
return 0; |
| 56 |
} |
| 57 |
diff --git a/regular-change.h b/regular-change.h |
| 58 |
index 111222..333444 100644 |
| 59 |
--- a/regular-change.h |
| 60 |
+++ b/regular-change.h |
| 61 |
@@ -1,2 +1,2 @@ |
| 62 |
-#define OLD_VERSION 1 |
| 63 |
+#define NEW_VERSION 2 |
| 64 |
/* header file */ |
| 65 |
EOF |
| 66 |
|
| 67 |
# Test 1: lsdiff should list all files correctly |
| 68 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include complex-git.patch 2>errors1 >result1 || exit 1 |
| 69 |
[ -s errors1 ] && exit 1 |
| 70 |
|
| 71 |
cat << EOF | cmp - result1 || exit 1 |
| 72 |
b/new-file.txt |
| 73 |
a/deleted-file.old |
| 74 |
a/binary-data.bin |
| 75 |
a/script-mode.sh |
| 76 |
b/new-name.txt |
| 77 |
a/copied-file.c |
| 78 |
a/regular-change.h |
| 79 |
EOF |
| 80 |
|
| 81 |
# Test 2: lsdiff with --git-prefixes=strip |
| 82 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include --git-prefixes=strip complex-git.patch 2>errors2 >result2 || exit 1 |
| 83 |
[ -s errors2 ] && exit 1 |
| 84 |
|
| 85 |
cat << EOF | cmp - result2 || exit 1 |
| 86 |
new-file.txt |
| 87 |
deleted-file.old |
| 88 |
binary-data.bin |
| 89 |
script-mode.sh |
| 90 |
new-name.txt |
| 91 |
copied-file.c |
| 92 |
regular-change.h |
| 93 |
EOF |
| 94 |
|
| 95 |
# Test 3: Filter only new files |
| 96 |
${FILTERDIFF} --git-extended-diffs=include -i "*/*.txt" complex-git.patch 2>errors3 >result3 || exit 1 |
| 97 |
[ -s errors3 ] && exit 1 |
| 98 |
|
| 99 |
# Should include new-file.txt and new-name.txt (renamed file) |
| 100 |
grep -q "new-file.txt" result3 || exit 1 |
| 101 |
grep -q "new-name.txt" result3 || exit 1 |
| 102 |
grep -q "binary-data.bin" result3 && exit 1 # Should not include binary |
| 103 |
|
| 104 |
# Test 4: Filter binary files specifically |
| 105 |
${FILTERDIFF} --git-extended-diffs=include -i "*/*.bin" complex-git.patch 2>errors4 >result4 || exit 1 |
| 106 |
[ -s errors4 ] && exit 1 |
| 107 |
|
| 108 |
cat << EOF | cmp - result4 || exit 1 |
| 109 |
diff --git a/binary-data.bin b/binary-data.bin |
| 110 |
new file mode 100644 |
| 111 |
index 0000000..1234567 |
| 112 |
Binary files /dev/null and b/binary-data.bin differ |
| 113 |
EOF |
| 114 |
|
| 115 |
# Test 5: Exclude deleted files |
| 116 |
${FILTERDIFF} --git-extended-diffs=include -x "*/*.old" complex-git.patch 2>errors5 >result5 || exit 1 |
| 117 |
[ -s errors5 ] && exit 1 |
| 118 |
|
| 119 |
# Should not contain deleted-file.old |
| 120 |
grep -q "deleted-file.old" result5 && exit 1 |
| 121 |
|
| 122 |
# Test 6: Test grepdiff on content changes only |
| 123 |
${GREPDIFF} --git-extended-diffs=include "NEW_VERSION" complex-git.patch 2>errors6 >result6 || exit 1 |
| 124 |
[ -s errors6 ] && exit 1 |
| 125 |
|
| 126 |
# Should only match regular-change.h |
| 127 |
grep -q "regular-change.h" result6 || exit 1 |
| 128 |
grep -q "new-file.txt" result6 && exit 1 # Should not match files without the pattern |
| 129 |
|
| 130 |
# Test 7: Test with -p strip on complex paths |
| 131 |
${FILTERDIFF} --git-extended-diffs=include --git-prefixes=strip -p0 --strip=0 complex-git.patch 2>errors7 >result7 || exit 1 |
| 132 |
[ -s errors7 ] && exit 1 |
| 133 |
|
| 134 |
# Should preserve all content |
| 135 |
grep -q "new-file.txt" result7 || exit 1 |
| 136 |
grep -q "binary-data.bin" result7 || exit 1 |
| 137 |
|
| 138 |
exit 0 |