| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Test for --git-prefixes option |
| 4 |
# This test ensures that the --git-prefixes option works correctly |
| 5 |
# for both strip and keep modes with various types of Git diffs |
| 6 |
|
| 7 |
. ${top_srcdir-.}/tests/common.sh |
| 8 |
|
| 9 |
# Create test patch with different types of Git diffs: |
| 10 |
# 1. Binary file (no hunks, uses diff --git line for filenames) |
| 11 |
# 2. File rename (uses "rename from/to" headers - no a/b/ prefixes) |
| 12 |
# 3. Mode-only change (no hunks, uses diff --git line for filenames) |
| 13 |
# 4. Regular file with content changes (has traditional --- +++ lines) |
| 14 |
cat << EOF > mixed-git.patch |
| 15 |
diff --git a/binary-file b/binary-file |
| 16 |
new file mode 100644 |
| 17 |
index 0000000..998a95d |
| 18 |
Binary files /dev/null and b/binary-file differ |
| 19 |
diff --git a/renamed-file b/new-name |
| 20 |
similarity index 100% |
| 21 |
rename from renamed-file |
| 22 |
rename to new-name |
| 23 |
diff --git a/mode-only.sh b/mode-only.sh |
| 24 |
old mode 100755 |
| 25 |
new mode 100644 |
| 26 |
diff --git a/regular-file.txt b/regular-file.txt |
| 27 |
index abcdefg..1234567 100644 |
| 28 |
--- a/regular-file.txt |
| 29 |
+++ b/regular-file.txt |
| 30 |
@@ -1,2 +1,2 @@ |
| 31 |
-old content |
| 32 |
+new content |
| 33 |
EOF |
| 34 |
|
| 35 |
# Test default behavior (keep prefixes) |
| 36 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include mixed-git.patch 2>errors1 >result1 || exit 1 |
| 37 |
[ -s errors1 ] && exit 1 |
| 38 |
|
| 39 |
# Expected output explanation: |
| 40 |
# - a/binary-file: from "diff --git a/binary-file b/binary-file" (keeps a/ prefix) |
| 41 |
# - b/new-name: best_name() chooses b/new-name over a/renamed-file (shorter basename: "new-name" vs "renamed-file") |
| 42 |
# - a/mode-only.sh: from "diff --git a/mode-only.sh b/mode-only.sh" (keeps a/ prefix) |
| 43 |
# - a/regular-file.txt: from "diff --git a/regular-file.txt b/regular-file.txt" (keeps a/ prefix) |
| 44 |
cat << EOF | cmp - result1 || exit 1 |
| 45 |
a/binary-file |
| 46 |
b/new-name |
| 47 |
a/mode-only.sh |
| 48 |
a/regular-file.txt |
| 49 |
EOF |
| 50 |
|
| 51 |
# Test --git-prefixes=keep (explicit) |
| 52 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include --git-prefixes=keep mixed-git.patch 2>errors2 >result2 || exit 1 |
| 53 |
[ -s errors2 ] && exit 1 |
| 54 |
|
| 55 |
cat << EOF | cmp - result2 || exit 1 |
| 56 |
a/binary-file |
| 57 |
b/new-name |
| 58 |
a/mode-only.sh |
| 59 |
a/regular-file.txt |
| 60 |
EOF |
| 61 |
|
| 62 |
# Test --git-prefixes=strip |
| 63 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include --git-prefixes=strip mixed-git.patch 2>errors3 >result3 || exit 1 |
| 64 |
[ -s errors3 ] && exit 1 |
| 65 |
|
| 66 |
# Expected output explanation: |
| 67 |
# - binary-file: from "diff --git a/binary-file b/binary-file" (strips a/ prefix) |
| 68 |
# - new-name: best_name() chooses "new-name" over "renamed-file" (shorter basename) |
| 69 |
# - mode-only.sh: from "diff --git a/mode-only.sh b/mode-only.sh" (strips a/ prefix) |
| 70 |
# - regular-file.txt: from "diff --git a/regular-file.txt b/regular-file.txt" (strips a/ prefix) |
| 71 |
cat << EOF | cmp - result3 || exit 1 |
| 72 |
binary-file |
| 73 |
new-name |
| 74 |
mode-only.sh |
| 75 |
regular-file.txt |
| 76 |
EOF |
| 77 |
|
| 78 |
# Test with filterdiff --git-prefixes=strip |
| 79 |
${FILTERDIFF} --git-extended-diffs=include --git-prefixes=strip -i "*.txt" mixed-git.patch 2>errors4 >result4 || exit 1 |
| 80 |
[ -s errors4 ] && exit 1 |
| 81 |
|
| 82 |
cat << EOF | cmp - result4 || exit 1 |
| 83 |
diff --git a/regular-file.txt b/regular-file.txt |
| 84 |
index abcdefg..1234567 100644 |
| 85 |
--- a/regular-file.txt |
| 86 |
+++ b/regular-file.txt |
| 87 |
@@ -1,2 +1,2 @@ |
| 88 |
-old content |
| 89 |
+new content |
| 90 |
EOF |
| 91 |
|
| 92 |
# Test with grepdiff --git-prefixes=strip |
| 93 |
${GREPDIFF} --git-extended-diffs=include --git-extended-diffs=include --git-prefixes=strip --output-matching=file "content" mixed-git.patch 2>errors5 >result5 || exit 1 |
| 94 |
[ -s errors5 ] && exit 1 |
| 95 |
|
| 96 |
cat << EOF | cmp - result5 || exit 1 |
| 97 |
diff --git a/regular-file.txt b/regular-file.txt |
| 98 |
index abcdefg..1234567 100644 |
| 99 |
--- a/regular-file.txt |
| 100 |
+++ b/regular-file.txt |
| 101 |
@@ -1,2 +1,2 @@ |
| 102 |
-old content |
| 103 |
+new content |
| 104 |
EOF |
| 105 |
|
| 106 |
# Test invalid argument |
| 107 |
${LSDIFF} --git-extended-diffs=include --git-extended-diffs=include --git-prefixes=invalid mixed-git.patch 2>errors6 >result6 |
| 108 |
[ $? -eq 1 ] || exit 1 |
| 109 |
grep -q "invalid argument to --git-prefixes" errors6 || exit 1 |
| 110 |
|
| 111 |
exit 0 |