Debian Codegraph @

tests/git-extended-diffs-exclude/run-test

raw
1 #!/bin/sh
2
3 # Test for --git-extended-diffs=exclude option
4 # Verifies that exclude mode matches 0.4.3 behavior by skipping
5 # git diffs without content hunks (renames, copies, mode-only, binary files)
6
7 . ${top_srcdir-.}/tests/common.sh
8
9 cat << EOF > mixed-git.patch
10 diff --git a/1-rename.txt b/1-rename-new.txt
11 similarity index 100%
12 rename from 1-rename.txt
13 rename to 1-rename-new.txt
14 diff --git a/2-copy.c b/2-copy-new.c
15 similarity index 95%
16 copy from 2-copy.c
17 copy to 2-copy-new.c
18 diff --git a/3-mode-only.sh b/3-mode-only.sh
19 old mode 100755
20 new mode 100644
21 diff --git a/4-binary.bin b/4-binary.bin
22 new file mode 100644
23 index 0000000..998a95d
24 Binary files /dev/null and b/4-binary.bin differ
25 diff --git a/5-normal.txt b/5-normal.txt
26 --- a/5-normal.txt
27 +++ b/5-normal.txt
28 @@ -1 +1 @@
29 -old
30 +new
31 diff --git a/6-another.txt b/6-another.txt
32 --- a/6-another.txt
33 +++ b/6-another.txt
34 @@ -1 +1 @@
35 -old
36 +new
37 EOF
38
39 # Test 1: Default should be exclude in 0.4.x (only show files with hunks)
40 ${LSDIFF} mixed-git.patch 2>errors1 >result1 || exit 1
41 [ -s errors1 ] && exit 1
42
43 cat << EOF | cmp - result1 || exit 1
44 a/5-normal.txt
45 a/6-another.txt
46 EOF
47
48 # Test 2: Explicit --git-extended-diffs=exclude
49 ${LSDIFF} --git-extended-diffs=exclude mixed-git.patch 2>errors2 >result2 || exit 1
50 [ -s errors2 ] && exit 1
51
52 cat << EOF | cmp - result2 || exit 1
53 a/5-normal.txt
54 a/6-another.txt
55 EOF
56
57 # Test 3: File numbering with exclude mode
58 ${LSDIFF} -N --git-extended-diffs=exclude mixed-git.patch 2>errors3 >result3 || exit 1
59 [ -s errors3 ] && exit 1
60
61 cat << EOF | cmp - result3 || exit 1
62 File #1 a/5-normal.txt
63 File #2 a/6-another.txt
64 EOF
65
66 # Test 4: filterdiff with exclude mode
67 ${FILTERDIFF} --git-extended-diffs=exclude -i "*normal*" mixed-git.patch 2>errors4 >result4 || exit 1
68 [ -s errors4 ] && exit 1
69
70 cat << EOF | cmp - result4 || exit 1
71 diff --git a/5-normal.txt b/5-normal.txt
72 --- a/5-normal.txt
73 +++ b/5-normal.txt
74 @@ -1 +1 @@
75 -old
76 +new
77 EOF
78
79 # Test 5: File number filtering works with exclude mode
80 ${FILTERDIFF} --git-extended-diffs=exclude -F 2 mixed-git.patch 2>errors5 >result5 || exit 1
81 [ -s errors5 ] && exit 1
82
83 cat << EOF | cmp - result5 || exit 1
84 diff --git a/6-another.txt b/6-another.txt
85 --- a/6-another.txt
86 +++ b/6-another.txt
87 @@ -1 +1 @@
88 -old
89 +new
90 EOF
91
92 # Test 6: Compare with include mode (should show all files)
93 ${LSDIFF} -N --git-extended-diffs=include mixed-git.patch 2>errors6 >result6 || exit 1
94 [ -s errors6 ] && exit 1
95
96 cat << EOF | cmp - result6 || exit 1
97 File #1 a/1-rename.txt
98 File #2 a/2-copy.c
99 File #3 a/3-mode-only.sh
100 File #4 a/4-binary.bin
101 File #5 a/5-normal.txt
102 File #6 a/6-another.txt
103 EOF
104
105 # Test 7: Coverage for GIT_DIFF_NORMAL case in should_skip_git_extended_diff()
106 # Normal git diffs should NOT be skipped in exclude mode
107 cat << EOF > normal-only.patch
108 diff --git a/file.txt b/file.txt
109 --- a/file.txt
110 +++ b/file.txt
111 @@ -1,3 +1,3 @@
112 line 1
113 -old line
114 +new line
115 line 3
116 EOF
117
118 ${FILTERDIFF} --git-extended-diffs=exclude normal-only.patch 2>errors7 >result7 || exit 1
119 [ -s errors7 ] && exit 1
120
121 cat << EOF | cmp - result7 || exit 1
122 diff --git a/file.txt b/file.txt
123 --- a/file.txt
124 +++ b/file.txt
125 @@ -1,3 +1,3 @@
126 line 1
127 -old line
128 +new line
129 line 3
130 EOF
131
132 # Test 8: Coverage for goto eof path when extended diff at EOF
133 # Patch ending with extended diff should skip to eof in exclude mode
134 cat << EOF > eof.patch
135 diff --git a/normal.txt b/normal.txt
136 --- a/normal.txt
137 +++ b/normal.txt
138 @@ -1 +1 @@
139 -old
140 +new
141 diff --git a/rename.txt b/rename-new.txt
142 similarity index 100%
143 rename from rename.txt
144 rename to rename-new.txt
145 EOF
146
147 ${FILTERDIFF} --git-extended-diffs=exclude eof.patch 2>errors8 >result8 || exit 1
148 [ -s errors8 ] && exit 1
149
150 # Should only show normal diff, not the rename at EOF
151 cat << EOF | cmp - result8 || exit 1
152 diff --git a/normal.txt b/normal.txt
153 --- a/normal.txt
154 +++ b/normal.txt
155 @@ -1 +1 @@
156 -old
157 +new
158 EOF
159
160 # Test 9: Coverage for invalid argument error path
161 # Invalid argument to --git-extended-diffs should error
162 ${FILTERDIFF} --git-extended-diffs=invalid mixed-git.patch 2>errors9 >result9 && exit 1
163
164 # Check error message
165 grep -q "invalid argument to --git-extended-diffs" errors9 || exit 1
166 grep -q "expected 'exclude' or 'include'" errors9 || exit 1
167
168 exit 0