| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Test core git diff status handling with lsdiff -s |
| 4 |
|
| 5 |
. ${top_srcdir-.}/tests/common.sh |
| 6 |
|
| 7 |
# Test 1: Git diff with new file (no hunks) - should show '+' |
| 8 |
cat << EOF > new-file-no-hunks.patch |
| 9 |
diff --git a/new-file.txt b/new-file.txt |
| 10 |
new file mode 100644 |
| 11 |
index 0000000..abcdef1 |
| 12 |
EOF |
| 13 |
|
| 14 |
${LSDIFF} --git-extended-diffs=include -s new-file-no-hunks.patch 2>errors1 >result1 || exit 1 |
| 15 |
[ -s errors1 ] && exit 1 |
| 16 |
|
| 17 |
cat << EOF | cmp - result1 || exit 1 |
| 18 |
+ a/new-file.txt |
| 19 |
EOF |
| 20 |
|
| 21 |
# Test 2: Git diff with deleted file (no hunks) - should show '-' |
| 22 |
cat << EOF > deleted-file-no-hunks.patch |
| 23 |
diff --git a/deleted-file.txt b/deleted-file.txt |
| 24 |
deleted file mode 100644 |
| 25 |
index abcdef1..0000000 |
| 26 |
EOF |
| 27 |
|
| 28 |
${LSDIFF} --git-extended-diffs=include -s deleted-file-no-hunks.patch 2>errors2 >result2 || exit 1 |
| 29 |
[ -s errors2 ] && exit 1 |
| 30 |
|
| 31 |
cat << EOF | cmp - result2 || exit 1 |
| 32 |
- a/deleted-file.txt |
| 33 |
EOF |
| 34 |
|
| 35 |
# Test 3: Git diff with new file (with hunks) - should show '+' |
| 36 |
cat << EOF > new-file-with-hunks.patch |
| 37 |
diff --git a/new-file-hunks.txt b/new-file-hunks.txt |
| 38 |
new file mode 100644 |
| 39 |
index 0000000..1234567 |
| 40 |
--- /dev/null |
| 41 |
+++ b/new-file-hunks.txt |
| 42 |
@@ -0,0 +1,3 @@ |
| 43 |
+line 1 |
| 44 |
+line 2 |
| 45 |
+line 3 |
| 46 |
EOF |
| 47 |
|
| 48 |
${LSDIFF} --git-extended-diffs=include -s new-file-with-hunks.patch 2>errors3 >result3 || exit 1 |
| 49 |
[ -s errors3 ] && exit 1 |
| 50 |
|
| 51 |
cat << EOF | cmp - result3 || exit 1 |
| 52 |
+ b/new-file-hunks.txt |
| 53 |
EOF |
| 54 |
|
| 55 |
# Test 4: Git diff with deleted file (with hunks) - should show '-' |
| 56 |
cat << EOF > deleted-file-with-hunks.patch |
| 57 |
diff --git a/deleted-file-hunks.txt b/deleted-file-hunks.txt |
| 58 |
deleted file mode 100644 |
| 59 |
index 1234567..0000000 |
| 60 |
--- a/deleted-file-hunks.txt |
| 61 |
+++ /dev/null |
| 62 |
@@ -1,3 +0,0 @@ |
| 63 |
-line 1 |
| 64 |
-line 2 |
| 65 |
-line 3 |
| 66 |
EOF |
| 67 |
|
| 68 |
${LSDIFF} --git-extended-diffs=include -s deleted-file-with-hunks.patch 2>errors4 >result4 || exit 1 |
| 69 |
[ -s errors4 ] && exit 1 |
| 70 |
|
| 71 |
cat << EOF | cmp - result4 || exit 1 |
| 72 |
- a/deleted-file-hunks.txt |
| 73 |
EOF |
| 74 |
|
| 75 |
# Test 5: Malformed git diff with index changes but no hunks (not normally produced by git) - produces no output |
| 76 |
cat << EOF > modified-file-no-hunks.patch |
| 77 |
diff --git a/modified-file.txt b/modified-file.txt |
| 78 |
index abcdef1..1234567 100644 |
| 79 |
EOF |
| 80 |
|
| 81 |
${LSDIFF} --git-extended-diffs=include -s modified-file-no-hunks.patch 2>errors5 >result5 || exit 1 |
| 82 |
[ -s errors5 ] && exit 1 |
| 83 |
|
| 84 |
# Should produce no output (empty file) |
| 85 |
[ ! -s result5 ] || exit 1 |
| 86 |
|
| 87 |
# Test 6: Git diff with regular modification (with hunks) - should show '!' |
| 88 |
cat << EOF > modified-file-with-hunks.patch |
| 89 |
diff --git a/modified-file-hunks.txt b/modified-file-hunks.txt |
| 90 |
index abcdef1..1234567 100644 |
| 91 |
--- a/modified-file-hunks.txt |
| 92 |
+++ b/modified-file-hunks.txt |
| 93 |
@@ -1,3 +1,3 @@ |
| 94 |
line 1 |
| 95 |
-old line |
| 96 |
+new line |
| 97 |
line 3 |
| 98 |
EOF |
| 99 |
|
| 100 |
${LSDIFF} --git-extended-diffs=include -s modified-file-with-hunks.patch 2>errors6 >result6 || exit 1 |
| 101 |
[ -s errors6 ] && exit 1 |
| 102 |
|
| 103 |
cat << EOF | cmp - result6 || exit 1 |
| 104 |
! a/modified-file-hunks.txt |
| 105 |
EOF |
| 106 |
|
| 107 |
# Test 7: Mixed git diff with multiple file types |
| 108 |
cat << EOF > mixed-git.patch |
| 109 |
diff --git a/new.txt b/new.txt |
| 110 |
new file mode 100644 |
| 111 |
index 0000000..abc123 |
| 112 |
--- /dev/null |
| 113 |
+++ b/new.txt |
| 114 |
@@ -0,0 +1 @@ |
| 115 |
+new content |
| 116 |
diff --git a/deleted.txt b/deleted.txt |
| 117 |
deleted file mode 100644 |
| 118 |
index def456..0000000 |
| 119 |
--- a/deleted.txt |
| 120 |
+++ /dev/null |
| 121 |
@@ -1 +0,0 @@ |
| 122 |
-deleted content |
| 123 |
diff --git a/modified.txt b/modified.txt |
| 124 |
index ghi789..jkl012 100644 |
| 125 |
--- a/modified.txt |
| 126 |
+++ b/modified.txt |
| 127 |
@@ -1 +1 @@ |
| 128 |
-old |
| 129 |
+new |
| 130 |
diff --git a/empty-new.txt b/empty-new.txt |
| 131 |
new file mode 100644 |
| 132 |
index 0000000..e69de29 |
| 133 |
diff --git a/empty-deleted.txt b/empty-deleted.txt |
| 134 |
deleted file mode 100644 |
| 135 |
index e69de29..0000000 |
| 136 |
EOF |
| 137 |
|
| 138 |
${LSDIFF} --git-extended-diffs=include -s mixed-git.patch 2>errors7 >result7 || exit 1 |
| 139 |
[ -s errors7 ] && exit 1 |
| 140 |
|
| 141 |
cat << EOF | cmp - result7 || exit 1 |
| 142 |
+ b/new.txt |
| 143 |
- a/deleted.txt |
| 144 |
! a/modified.txt |
| 145 |
+ a/empty-new.txt |
| 146 |
- a/empty-deleted.txt |
| 147 |
EOF |
| 148 |
|
| 149 |
# Test 8: Test with filterdiff in list mode (should use same code paths) |
| 150 |
${FILTERDIFF} --git-extended-diffs=include --list -s mixed-git.patch 2>errors8 >result8 || exit 1 |
| 151 |
[ -s errors8 ] && exit 1 |
| 152 |
|
| 153 |
# Should be identical to lsdiff -s output |
| 154 |
cmp result7 result8 || exit 1 |