| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Test for GIT_DIFF_RENAME functionality (similarity index 100%) |
| 4 |
|
| 5 |
. ${top_srcdir-.}/tests/common.sh |
| 6 |
|
| 7 |
# Test 1: Pure rename (similarity index 100%) |
| 8 |
cat << 'EOF' > git-pure-rename.patch |
| 9 |
diff --git a/old-name.txt b/new-name.txt |
| 10 |
similarity index 100% |
| 11 |
rename from old-name.txt |
| 12 |
rename to new-name.txt |
| 13 |
EOF |
| 14 |
|
| 15 |
# Test 2: Rename with similarity < 100% (should be treated as copy) |
| 16 |
cat << 'EOF' > git-rename-with-changes.patch |
| 17 |
diff --git a/original.c b/modified.c |
| 18 |
similarity index 85% |
| 19 |
rename from original.c |
| 20 |
rename to modified.c |
| 21 |
index abc123..def456 100644 |
| 22 |
--- a/original.c |
| 23 |
+++ b/modified.c |
| 24 |
@@ -1,5 +1,6 @@ |
| 25 |
#include <stdio.h> |
| 26 |
|
| 27 |
int main() { |
| 28 |
+ printf("Modified!\n"); |
| 29 |
return 0; |
| 30 |
} |
| 31 |
EOF |
| 32 |
|
| 33 |
# Test 3: Multiple pure renames |
| 34 |
cat << 'EOF' > git-multiple-renames.patch |
| 35 |
diff --git a/file1.txt b/renamed1.txt |
| 36 |
similarity index 100% |
| 37 |
rename from file1.txt |
| 38 |
rename to renamed1.txt |
| 39 |
diff --git a/file2.txt b/renamed2.txt |
| 40 |
similarity index 100% |
| 41 |
rename from file2.txt |
| 42 |
rename to renamed2.txt |
| 43 |
EOF |
| 44 |
|
| 45 |
# Test 4: Rename in subdirectory |
| 46 |
cat << 'EOF' > git-rename-subdir.patch |
| 47 |
diff --git a/src/old.c b/src/new.c |
| 48 |
similarity index 100% |
| 49 |
rename from src/old.c |
| 50 |
rename to src/new.c |
| 51 |
EOF |
| 52 |
|
| 53 |
echo "=== Test 1: lsdiff with pure rename ===" |
| 54 |
${LSDIFF} --git-extended-diffs=include -s git-pure-rename.patch 2>errors1 >result1 || exit 1 |
| 55 |
[ -s errors1 ] && exit 1 |
| 56 |
|
| 57 |
# For pure renames, both files exist so status should be '!' |
| 58 |
# With --git-prefixes=keep (default), rename operations now use a/ prefix |
| 59 |
cat << EOF | cmp - result1 || exit 1 |
| 60 |
! a/old-name.txt |
| 61 |
EOF |
| 62 |
|
| 63 |
echo "=== Test 2: filterdiff include pure rename ===" |
| 64 |
${FILTERDIFF} --git-extended-diffs=include -i "a/old*" git-pure-rename.patch 2>errors2 >result2 || exit 1 |
| 65 |
[ -s errors2 ] && exit 1 |
| 66 |
|
| 67 |
cat << 'EOF' | cmp - result2 || exit 1 |
| 68 |
diff --git a/old-name.txt b/new-name.txt |
| 69 |
similarity index 100% |
| 70 |
rename from old-name.txt |
| 71 |
rename to new-name.txt |
| 72 |
EOF |
| 73 |
|
| 74 |
echo "=== Test 3: filterdiff include by new name (should not match) ===" |
| 75 |
${FILTERDIFF} --git-extended-diffs=include -i "new*" git-pure-rename.patch 2>errors3 >result3 || exit 1 |
| 76 |
[ -s errors3 ] && exit 1 |
| 77 |
|
| 78 |
# Should be empty because best_name() chooses a/old-name.txt, which doesn't match "new*" |
| 79 |
[ -s result3 ] && exit 1 |
| 80 |
|
| 81 |
echo "=== Test 4: filterdiff exclude pure rename ===" |
| 82 |
${FILTERDIFF} --git-extended-diffs=include -x "*name*" git-pure-rename.patch 2>errors4 >result4 || exit 1 |
| 83 |
[ -s errors4 ] && exit 1 |
| 84 |
|
| 85 |
# Should be empty |
| 86 |
[ -s result4 ] && exit 1 |
| 87 |
|
| 88 |
echo "=== Test 5: lsdiff with rename that has changes ===" |
| 89 |
${LSDIFF} --git-extended-diffs=include -s git-rename-with-changes.patch 2>errors5 >result5 || exit 1 |
| 90 |
[ -s errors5 ] && exit 1 |
| 91 |
|
| 92 |
cat << EOF | cmp - result5 || exit 1 |
| 93 |
! a/original.c |
| 94 |
EOF |
| 95 |
|
| 96 |
echo "=== Test 6: lsdiff with multiple renames ===" |
| 97 |
${LSDIFF} --git-extended-diffs=include -s git-multiple-renames.patch 2>errors6 >result6 || exit 1 |
| 98 |
[ -s errors6 ] && exit 1 |
| 99 |
|
| 100 |
cat << EOF | cmp - result6 || exit 1 |
| 101 |
! a/file1.txt |
| 102 |
! a/file2.txt |
| 103 |
EOF |
| 104 |
|
| 105 |
echo "=== Test 7: filterdiff with pattern matching one of multiple renames ===" |
| 106 |
${FILTERDIFF} --git-extended-diffs=include -i "a/file1*" git-multiple-renames.patch 2>errors7 >result7 || exit 1 |
| 107 |
[ -s errors7 ] && exit 1 |
| 108 |
|
| 109 |
cat << 'EOF' | cmp - result7 || exit 1 |
| 110 |
diff --git a/file1.txt b/renamed1.txt |
| 111 |
similarity index 100% |
| 112 |
rename from file1.txt |
| 113 |
rename to renamed1.txt |
| 114 |
EOF |
| 115 |
|
| 116 |
echo "=== Test 8: filterdiff with subdirectory rename ===" |
| 117 |
${FILTERDIFF} --git-extended-diffs=include -i "a/src/*" git-rename-subdir.patch 2>errors8 >result8 || exit 1 |
| 118 |
[ -s errors8 ] && exit 1 |
| 119 |
|
| 120 |
cat << 'EOF' | cmp - result8 || exit 1 |
| 121 |
diff --git a/src/old.c b/src/new.c |
| 122 |
similarity index 100% |
| 123 |
rename from src/old.c |
| 124 |
rename to src/new.c |
| 125 |
EOF |
| 126 |
|
| 127 |
echo "=== Test 9: Test git-prefixes=strip with renames ===" |
| 128 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include --git-prefixes=strip -s git-pure-rename.patch 2>errors9 >result9 || exit 1 |
| 129 |
[ -s errors9 ] && exit 1 |
| 130 |
|
| 131 |
cat << EOF | cmp - result9 || exit 1 |
| 132 |
! old-name.txt |
| 133 |
EOF |
| 134 |
|
| 135 |
echo "=== Test 10: Test git-prefixes=strip with filterdiff ===" |
| 136 |
${FILTERDIFF} --git-extended-diffs=include --git-prefixes=strip -i "old*" git-pure-rename.patch 2>errors10 >result10 || exit 1 |
| 137 |
[ -s errors10 ] && exit 1 |
| 138 |
|
| 139 |
cat << 'EOF' | cmp - result10 || exit 1 |
| 140 |
diff --git a/old-name.txt b/new-name.txt |
| 141 |
similarity index 100% |
| 142 |
rename from old-name.txt |
| 143 |
rename to new-name.txt |
| 144 |
EOF |
| 145 |
|
| 146 |
# Skip grepdiff test - pure renames have no content to grep |
| 147 |
|
| 148 |
echo "All pure rename tests passed!" |
| 149 |
exit 0 |