| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Test git copy operations (similarity < 100%) |
| 4 |
# This test covers file copies with modifications |
| 5 |
|
| 6 |
. ${top_srcdir-.}/tests/common.sh |
| 7 |
|
| 8 |
# Test 1: Basic copy operation with modifications |
| 9 |
cat << EOF > copy-basic.patch |
| 10 |
diff --git a/original.c b/copy1.c |
| 11 |
similarity index 85% |
| 12 |
copy from original.c |
| 13 |
copy to copy1.c |
| 14 |
index abc123..def456 100644 |
| 15 |
--- a/original.c |
| 16 |
+++ b/copy1.c |
| 17 |
@@ -1,5 +1,6 @@ |
| 18 |
#include <stdio.h> |
| 19 |
|
| 20 |
int main() { |
| 21 |
+ printf("This is a copy\\n"); |
| 22 |
return 0; |
| 23 |
} |
| 24 |
EOF |
| 25 |
|
| 26 |
# Test lsdiff with copy operation |
| 27 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include copy-basic.patch 2>errors1 >result1 || exit 1 |
| 28 |
[ -s errors1 ] && exit 1 |
| 29 |
|
| 30 |
cat << EOF | cmp - result1 || exit 1 |
| 31 |
b/copy1.c |
| 32 |
EOF |
| 33 |
|
| 34 |
# Test filterdiff with copy operation |
| 35 |
${FILTERDIFF} --git-extended-diffs=include -i "b/copy1.c" copy-basic.patch 2>errors2 >result2 || exit 1 |
| 36 |
[ -s errors2 ] && exit 1 |
| 37 |
|
| 38 |
cat << EOF | cmp - result2 || exit 1 |
| 39 |
diff --git a/original.c b/copy1.c |
| 40 |
similarity index 85% |
| 41 |
copy from original.c |
| 42 |
copy to copy1.c |
| 43 |
index abc123..def456 100644 |
| 44 |
--- a/original.c |
| 45 |
+++ b/copy1.c |
| 46 |
@@ -1,5 +1,6 @@ |
| 47 |
#include <stdio.h> |
| 48 |
|
| 49 |
int main() { |
| 50 |
+ printf("This is a copy\\n"); |
| 51 |
return 0; |
| 52 |
} |
| 53 |
EOF |
| 54 |
|
| 55 |
# Test 2: Multiple copy operations in one patch |
| 56 |
cat << EOF > copy-multiple.patch |
| 57 |
diff --git a/base.h b/copy1.h |
| 58 |
similarity index 90% |
| 59 |
copy from base.h |
| 60 |
copy to copy1.h |
| 61 |
index 111222..333444 100644 |
| 62 |
--- a/base.h |
| 63 |
+++ b/copy1.h |
| 64 |
@@ -1,3 +1,4 @@ |
| 65 |
#ifndef BASE_H |
| 66 |
#define BASE_H |
| 67 |
+#define COPY1_VERSION 1 |
| 68 |
#endif |
| 69 |
diff --git a/base.h b/copy2.h |
| 70 |
similarity index 80% |
| 71 |
copy from base.h |
| 72 |
copy to copy2.h |
| 73 |
index 111222..555666 100644 |
| 74 |
--- a/base.h |
| 75 |
+++ b/copy2.h |
| 76 |
@@ -1,3 +1,5 @@ |
| 77 |
#ifndef BASE_H |
| 78 |
#define BASE_H |
| 79 |
+#define COPY2_VERSION 2 |
| 80 |
+#define EXTRA_FEATURE |
| 81 |
#endif |
| 82 |
EOF |
| 83 |
|
| 84 |
# Test lsdiff with multiple copies |
| 85 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include copy-multiple.patch 2>errors3 >result3 || exit 1 |
| 86 |
[ -s errors3 ] && exit 1 |
| 87 |
|
| 88 |
cat << EOF | cmp - result3 || exit 1 |
| 89 |
a/base.h |
| 90 |
a/base.h |
| 91 |
EOF |
| 92 |
|
| 93 |
# Test filtering by source file (matches both copies) |
| 94 |
${FILTERDIFF} --git-extended-diffs=include -i "a/base.h" copy-multiple.patch 2>errors4 >result4 || exit 1 |
| 95 |
[ -s errors4 ] && exit 1 |
| 96 |
|
| 97 |
grep -q "copy2.h" result4 || exit 1 |
| 98 |
grep -q "copy1.h" result4 || exit 1 |
| 99 |
|
| 100 |
# Test 3: Copy with --git-prefixes=strip |
| 101 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include --git-prefixes=strip copy-multiple.patch 2>errors5 >result5 || exit 1 |
| 102 |
[ -s errors5 ] && exit 1 |
| 103 |
|
| 104 |
cat << EOF | cmp - result5 || exit 1 |
| 105 |
base.h |
| 106 |
base.h |
| 107 |
EOF |
| 108 |
|
| 109 |
# Test 4: Copy operation with binary file |
| 110 |
cat << EOF > copy-binary.patch |
| 111 |
diff --git a/data.bin b/backup.bin |
| 112 |
similarity index 100% |
| 113 |
copy from data.bin |
| 114 |
copy to backup.bin |
| 115 |
Binary files a/data.bin and b/backup.bin differ |
| 116 |
EOF |
| 117 |
|
| 118 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include copy-binary.patch 2>errors6 >result6 || exit 1 |
| 119 |
[ -s errors6 ] && exit 1 |
| 120 |
|
| 121 |
cat << EOF | cmp - result6 || exit 1 |
| 122 |
a/data.bin |
| 123 |
EOF |
| 124 |
|
| 125 |
${FILTERDIFF} --git-extended-diffs=include -i "a/data.bin" copy-binary.patch 2>errors7 >result7 || exit 1 |
| 126 |
[ -s errors7 ] && exit 1 |
| 127 |
|
| 128 |
cat << EOF | cmp - result7 || exit 1 |
| 129 |
diff --git a/data.bin b/backup.bin |
| 130 |
similarity index 100% |
| 131 |
copy from data.bin |
| 132 |
copy to backup.bin |
| 133 |
Binary files a/data.bin and b/backup.bin differ |
| 134 |
EOF |
| 135 |
|
| 136 |
# Test 5: Mixed copy and rename operations |
| 137 |
cat << EOF > copy-rename-mixed.patch |
| 138 |
diff --git a/file1.txt b/file1-copy.txt |
| 139 |
similarity index 75% |
| 140 |
copy from file1.txt |
| 141 |
copy to file1-copy.txt |
| 142 |
index abc123..def456 100644 |
| 143 |
--- a/file1.txt |
| 144 |
+++ b/file1-copy.txt |
| 145 |
@@ -1,2 +1,3 @@ |
| 146 |
original content |
| 147 |
+copied and modified |
| 148 |
end |
| 149 |
diff --git a/file2.txt b/file2-renamed.txt |
| 150 |
similarity index 100% |
| 151 |
rename from file2.txt |
| 152 |
rename to file2-renamed.txt |
| 153 |
EOF |
| 154 |
|
| 155 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include copy-rename-mixed.patch 2>errors8 >result8 || exit 1 |
| 156 |
[ -s errors8 ] && exit 1 |
| 157 |
|
| 158 |
cat << EOF | cmp - result8 || exit 1 |
| 159 |
a/file1.txt |
| 160 |
a/file2.txt |
| 161 |
EOF |
| 162 |
|
| 163 |
# Test 6: Copy with very low similarity |
| 164 |
cat << EOF > copy-low-similarity.patch |
| 165 |
diff --git a/template.c b/heavily-modified.c |
| 166 |
similarity index 15% |
| 167 |
copy from template.c |
| 168 |
copy to heavily-modified.c |
| 169 |
index abc123..xyz789 100644 |
| 170 |
--- a/template.c |
| 171 |
+++ b/heavily-modified.c |
| 172 |
@@ -1,10 +1,20 @@ |
| 173 |
#include <stdio.h> |
| 174 |
+#include <stdlib.h> |
| 175 |
+#include <string.h> |
| 176 |
+#include <unistd.h> |
| 177 |
|
| 178 |
-int main() { |
| 179 |
- return 0; |
| 180 |
+int main(int argc, char **argv) { |
| 181 |
+ if (argc < 2) { |
| 182 |
+ fprintf(stderr, "Usage: %s <arg>\\n", argv[0]); |
| 183 |
+ return 1; |
| 184 |
+ } |
| 185 |
+ |
| 186 |
+ printf("Processing: %s\\n", argv[1]); |
| 187 |
+ // Heavy modifications here |
| 188 |
+ return 0; |
| 189 |
} |
| 190 |
EOF |
| 191 |
|
| 192 |
${FILTERDIFF} --git-extended-diffs=include copy-low-similarity.patch 2>errors9 >result9 || exit 1 |
| 193 |
[ -s errors9 ] && exit 1 |
| 194 |
|
| 195 |
grep -q "heavily-modified.c" result9 || exit 1 |
| 196 |
grep -q "similarity index 15%" result9 || exit 1 |
| 197 |
|
| 198 |
exit 0 |