]>
Commit | Line | Data |
---|---|---|
8884cf15 TR |
1 | #!/bin/sh |
2 | ||
3 | test_description='range-diff tests' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | # Note that because of the range-diff's heuristics, test_commit does more | |
8 | # harm than good. We need some real history. | |
9 | ||
10 | test_expect_success 'setup' ' | |
11 | git fast-import < "$TEST_DIRECTORY"/t3206/history.export | |
12 | ' | |
13 | ||
14 | test_expect_success 'simple A..B A..C (unmodified)' ' | |
15 | git range-diff --no-color master..topic master..unmodified \ | |
16 | >actual && | |
17 | cat >expected <<-EOF && | |
18 | 1: 4de457d = 1: 35b9b25 s/5/A/ | |
19 | 2: fccce22 = 2: de345ab s/4/A/ | |
20 | 3: 147e64e = 3: 9af6654 s/11/B/ | |
21 | 4: a63e992 = 4: 2901f77 s/12/B/ | |
22 | EOF | |
23 | test_cmp expected actual | |
24 | ' | |
25 | ||
26 | test_expect_success 'simple B...C (unmodified)' ' | |
27 | git range-diff --no-color topic...unmodified >actual && | |
28 | # same "expected" as above | |
29 | test_cmp expected actual | |
30 | ' | |
31 | ||
32 | test_expect_success 'simple A B C (unmodified)' ' | |
33 | git range-diff --no-color master topic unmodified >actual && | |
34 | # same "expected" as above | |
35 | test_cmp expected actual | |
36 | ' | |
37 | ||
38 | test_expect_success 'trivial reordering' ' | |
39 | git range-diff --no-color master topic reordered >actual && | |
40 | cat >expected <<-EOF && | |
41 | 1: 4de457d = 1: aca177a s/5/A/ | |
42 | 3: 147e64e = 2: 14ad629 s/11/B/ | |
43 | 4: a63e992 = 3: ee58208 s/12/B/ | |
44 | 2: fccce22 = 4: 307b27a s/4/A/ | |
45 | EOF | |
46 | test_cmp expected actual | |
47 | ' | |
48 | ||
49 | test_expect_success 'removed a commit' ' | |
50 | git range-diff --no-color master topic removed >actual && | |
51 | cat >expected <<-EOF && | |
52 | 1: 4de457d = 1: 7657159 s/5/A/ | |
53 | 2: fccce22 < -: ------- s/4/A/ | |
54 | 3: 147e64e = 2: 43d84d3 s/11/B/ | |
55 | 4: a63e992 = 3: a740396 s/12/B/ | |
56 | EOF | |
57 | test_cmp expected actual | |
58 | ' | |
59 | ||
60 | test_expect_success 'added a commit' ' | |
61 | git range-diff --no-color master topic added >actual && | |
62 | cat >expected <<-EOF && | |
63 | 1: 4de457d = 1: 2716022 s/5/A/ | |
64 | 2: fccce22 = 2: b62accd s/4/A/ | |
65 | -: ------- > 3: df46cfa s/6/A/ | |
66 | 3: 147e64e = 4: 3e64548 s/11/B/ | |
67 | 4: a63e992 = 5: 12b4063 s/12/B/ | |
68 | EOF | |
69 | test_cmp expected actual | |
70 | ' | |
71 | ||
72 | test_expect_success 'new base, A B C' ' | |
73 | git range-diff --no-color master topic rebased >actual && | |
74 | cat >expected <<-EOF && | |
75 | 1: 4de457d = 1: cc9c443 s/5/A/ | |
76 | 2: fccce22 = 2: c5d9641 s/4/A/ | |
77 | 3: 147e64e = 3: 28cc2b6 s/11/B/ | |
78 | 4: a63e992 = 4: 5628ab7 s/12/B/ | |
79 | EOF | |
80 | test_cmp expected actual | |
81 | ' | |
82 | ||
83 | test_expect_success 'new base, B...C' ' | |
84 | # this syntax includes the commits from master! | |
85 | git range-diff --no-color topic...rebased >actual && | |
86 | cat >expected <<-EOF && | |
87 | -: ------- > 1: a31b12e unrelated | |
88 | 1: 4de457d = 2: cc9c443 s/5/A/ | |
89 | 2: fccce22 = 3: c5d9641 s/4/A/ | |
90 | 3: 147e64e = 4: 28cc2b6 s/11/B/ | |
91 | 4: a63e992 = 5: 5628ab7 s/12/B/ | |
92 | EOF | |
93 | test_cmp expected actual | |
94 | ' | |
95 | ||
96 | test_expect_success 'changed commit' ' | |
97 | git range-diff --no-color topic...changed >actual && | |
98 | cat >expected <<-EOF && | |
99 | 1: 4de457d = 1: a4b3333 s/5/A/ | |
100 | 2: fccce22 = 2: f51d370 s/4/A/ | |
101 | 3: 147e64e ! 3: 0559556 s/11/B/ | |
499352c2 | 102 | @@ file: A |
8884cf15 TR |
103 | 9 |
104 | 10 | |
105 | -11 | |
106 | -+B | |
107 | ++BB | |
108 | 12 | |
109 | 13 | |
110 | 14 | |
111 | 4: a63e992 ! 4: d966c5c s/12/B/ | |
499352c2 | 112 | @@ file |
444e0969 | 113 | @@ file: A |
8884cf15 TR |
114 | 9 |
115 | 10 | |
116 | - B | |
117 | + BB | |
118 | -12 | |
119 | +B | |
120 | 13 | |
121 | EOF | |
122 | test_cmp expected actual | |
123 | ' | |
124 | ||
4624185a ÆAB |
125 | test_expect_success 'changed commit with --no-patch diff option' ' |
126 | git range-diff --no-color --no-patch topic...changed >actual && | |
127 | cat >expected <<-EOF && | |
128 | 1: 4de457d = 1: a4b3333 s/5/A/ | |
129 | 2: fccce22 = 2: f51d370 s/4/A/ | |
130 | 3: 147e64e ! 3: 0559556 s/11/B/ | |
131 | 4: a63e992 ! 4: d966c5c s/12/B/ | |
132 | EOF | |
133 | test_cmp expected actual | |
134 | ' | |
135 | ||
136 | test_expect_success 'changed commit with --stat diff option' ' | |
4624185a ÆAB |
137 | git range-diff --no-color --stat topic...changed >actual && |
138 | cat >expected <<-EOF && | |
139 | 1: 4de457d = 1: a4b3333 s/5/A/ | |
140 | a => b | 0 | |
141 | 1 file changed, 0 insertions(+), 0 deletions(-) | |
4624185a ÆAB |
142 | 2: fccce22 = 2: f51d370 s/4/A/ |
143 | a => b | 0 | |
144 | 1 file changed, 0 insertions(+), 0 deletions(-) | |
4624185a ÆAB |
145 | 3: 147e64e ! 3: 0559556 s/11/B/ |
146 | a => b | 0 | |
147 | 1 file changed, 0 insertions(+), 0 deletions(-) | |
4624185a ÆAB |
148 | 4: a63e992 ! 4: d966c5c s/12/B/ |
149 | a => b | 0 | |
150 | 1 file changed, 0 insertions(+), 0 deletions(-) | |
4624185a ÆAB |
151 | EOF |
152 | test_cmp expected actual | |
153 | ' | |
154 | ||
0e573e8f LDM |
155 | test_expect_success 'changed commit with sm config' ' |
156 | git range-diff --no-color --submodule=log topic...changed >actual && | |
157 | cat >expected <<-EOF && | |
158 | 1: 4de457d = 1: a4b3333 s/5/A/ | |
159 | 2: fccce22 = 2: f51d370 s/4/A/ | |
160 | 3: 147e64e ! 3: 0559556 s/11/B/ | |
499352c2 | 161 | @@ file: A |
0e573e8f LDM |
162 | 9 |
163 | 10 | |
164 | -11 | |
165 | -+B | |
166 | ++BB | |
167 | 12 | |
168 | 13 | |
169 | 14 | |
170 | 4: a63e992 ! 4: d966c5c s/12/B/ | |
499352c2 | 171 | @@ file |
444e0969 | 172 | @@ file: A |
0e573e8f LDM |
173 | 9 |
174 | 10 | |
175 | - B | |
176 | + BB | |
177 | -12 | |
178 | +B | |
179 | 13 | |
180 | EOF | |
181 | test_cmp expected actual | |
182 | ' | |
183 | ||
b66885a3 TG |
184 | test_expect_success 'renamed file' ' |
185 | git range-diff --no-color --submodule=log topic...renamed-file >actual && | |
186 | sed s/Z/\ /g >expected <<-EOF && | |
187 | 1: 4de457d = 1: f258d75 s/5/A/ | |
188 | 2: fccce22 ! 2: 017b62d s/4/A/ | |
499352c2 | 189 | @@ Metadata |
b66885a3 TG |
190 | ZAuthor: Thomas Rast <trast@inf.ethz.ch> |
191 | Z | |
499352c2 | 192 | Z ## Commit message ## |
b66885a3 TG |
193 | - s/4/A/ |
194 | + s/4/A/ + rename file | |
195 | Z | |
196 | - ## file ## | |
197 | + ## file => renamed-file ## | |
198 | Z@@ | |
199 | Z 1 | |
200 | Z 2 | |
201 | 3: 147e64e ! 3: 3ce7af6 s/11/B/ | |
499352c2 TG |
202 | @@ Metadata |
203 | Z ## Commit message ## | |
b66885a3 TG |
204 | Z s/11/B/ |
205 | Z | |
206 | - ## file ## | |
444e0969 | 207 | -@@ file: A |
b66885a3 | 208 | + ## renamed-file ## |
444e0969 | 209 | +@@ renamed-file: A |
b66885a3 TG |
210 | Z 8 |
211 | Z 9 | |
444e0969 | 212 | Z 10 |
b66885a3 | 213 | 4: a63e992 ! 4: 1e6226b s/12/B/ |
499352c2 TG |
214 | @@ Metadata |
215 | Z ## Commit message ## | |
b66885a3 TG |
216 | Z s/12/B/ |
217 | Z | |
218 | - ## file ## | |
444e0969 | 219 | -@@ file: A |
b66885a3 | 220 | + ## renamed-file ## |
444e0969 | 221 | +@@ renamed-file: A |
b66885a3 TG |
222 | Z 9 |
223 | Z 10 | |
444e0969 | 224 | Z B |
b66885a3 TG |
225 | EOF |
226 | test_cmp expected actual | |
227 | ' | |
228 | ||
229 | test_expect_success 'file added and later removed' ' | |
230 | git range-diff --no-color --submodule=log topic...added-removed >actual && | |
231 | sed s/Z/\ /g >expected <<-EOF && | |
232 | 1: 4de457d = 1: 096b1ba s/5/A/ | |
233 | 2: fccce22 ! 2: d92e698 s/4/A/ | |
499352c2 | 234 | @@ Metadata |
b66885a3 TG |
235 | ZAuthor: Thomas Rast <trast@inf.ethz.ch> |
236 | Z | |
499352c2 | 237 | Z ## Commit message ## |
b66885a3 TG |
238 | - s/4/A/ |
239 | + s/4/A/ + new-file | |
240 | Z | |
241 | Z ## file ## | |
242 | Z@@ | |
499352c2 | 243 | @@ file |
b66885a3 TG |
244 | Z A |
245 | Z 6 | |
246 | Z 7 | |
247 | + | |
248 | + ## new-file (new) ## | |
249 | 3: 147e64e ! 3: 9a1db4d s/11/B/ | |
499352c2 | 250 | @@ Metadata |
b66885a3 TG |
251 | ZAuthor: Thomas Rast <trast@inf.ethz.ch> |
252 | Z | |
499352c2 | 253 | Z ## Commit message ## |
b66885a3 TG |
254 | - s/11/B/ |
255 | + s/11/B/ + remove file | |
256 | Z | |
257 | Z ## file ## | |
444e0969 | 258 | Z@@ file: A |
499352c2 | 259 | @@ file: A |
b66885a3 TG |
260 | Z 12 |
261 | Z 13 | |
262 | Z 14 | |
263 | + | |
264 | + ## new-file (deleted) ## | |
265 | 4: a63e992 = 4: fea3b5c s/12/B/ | |
266 | EOF | |
267 | test_cmp expected actual | |
268 | ' | |
269 | ||
51bbcda1 JH |
270 | test_expect_success 'no commits on one side' ' |
271 | git commit --amend -m "new message" && | |
272 | git range-diff master HEAD@{1} HEAD | |
273 | ' | |
274 | ||
8884cf15 TR |
275 | test_expect_success 'changed message' ' |
276 | git range-diff --no-color topic...changed-message >actual && | |
277 | sed s/Z/\ /g >expected <<-EOF && | |
278 | 1: 4de457d = 1: f686024 s/5/A/ | |
279 | 2: fccce22 ! 2: 4ab067d s/4/A/ | |
499352c2 TG |
280 | @@ Metadata |
281 | Z ## Commit message ## | |
8884cf15 TR |
282 | Z s/4/A/ |
283 | Z | |
284 | + Also a silly comment here! | |
285 | + | |
b66885a3 TG |
286 | Z ## file ## |
287 | Z@@ | |
288 | Z 1 | |
8884cf15 TR |
289 | 3: 147e64e = 3: b9cb956 s/11/B/ |
290 | 4: a63e992 = 4: 8add5f1 s/12/B/ | |
291 | EOF | |
292 | test_cmp expected actual | |
293 | ' | |
294 | ||
c5e64caa SB |
295 | test_expect_success 'dual-coloring' ' |
296 | sed -e "s|^:||" >expect <<-\EOF && | |
297 | :<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET> | |
298 | :<RED>2: f51d370 <RESET><YELLOW>!<RESET><GREEN> 2: 4ab067d<RESET><YELLOW> s/4/A/<RESET> | |
499352c2 TG |
299 | : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET> |
300 | : ## Commit message ##<RESET> | |
c5e64caa SB |
301 | : s/4/A/<RESET> |
302 | : <RESET> | |
303 | : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET> | |
29ef759d | 304 | : <REVERSE><GREEN>+<RESET> |
b66885a3 TG |
305 | : ## file ##<RESET> |
306 | : <CYAN> @@<RESET> | |
307 | : 1<RESET> | |
c5e64caa | 308 | :<RED>3: 0559556 <RESET><YELLOW>!<RESET><GREEN> 3: b9cb956<RESET><YELLOW> s/11/B/<RESET> |
499352c2 | 309 | : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET> |
c5e64caa SB |
310 | : 9<RESET> |
311 | : 10<RESET> | |
312 | : <RED> -11<RESET> | |
313 | : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET> | |
314 | : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET> | |
315 | : 12<RESET> | |
316 | : 13<RESET> | |
317 | : 14<RESET> | |
318 | :<RED>4: d966c5c <RESET><YELLOW>!<RESET><GREEN> 4: 8add5f1<RESET><YELLOW> s/12/B/<RESET> | |
499352c2 | 319 | : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET> |
444e0969 | 320 | : <CYAN> @@ file: A<RESET> |
c5e64caa SB |
321 | : 9<RESET> |
322 | : 10<RESET> | |
323 | : <REVERSE><RED>-<RESET><FAINT> BB<RESET> | |
324 | : <REVERSE><GREEN>+<RESET><BOLD> B<RESET> | |
325 | : <RED> -12<RESET> | |
326 | : <GREEN> +B<RESET> | |
327 | : 13<RESET> | |
328 | EOF | |
329 | git range-diff changed...changed-message --color --dual-color >actual.raw && | |
330 | test_decode_color >actual <actual.raw && | |
331 | test_cmp expect actual | |
332 | ' | |
333 | ||
2e6fd71a | 334 | for prev in topic master..topic |
31e2617a ES |
335 | do |
336 | test_expect_success "format-patch --range-diff=$prev" ' | |
ac0edf1f | 337 | git format-patch --cover-letter --range-diff=$prev \ |
31e2617a | 338 | master..unmodified >actual && |
ac0edf1f MÅ |
339 | test_when_finished "rm 000?-*" && |
340 | test_line_count = 5 actual && | |
341 | test_i18ngrep "^Range-diff:$" 0000-* && | |
342 | grep "= 1: .* s/5/A" 0000-* && | |
343 | grep "= 2: .* s/4/A" 0000-* && | |
344 | grep "= 3: .* s/11/B" 0000-* && | |
345 | grep "= 4: .* s/12/B" 0000-* | |
31e2617a ES |
346 | ' |
347 | done | |
348 | ||
cdc067c3 | 349 | test_expect_success 'format-patch --range-diff as commentary' ' |
ac0edf1f MÅ |
350 | git format-patch --range-diff=HEAD~1 HEAD~1 >actual && |
351 | test_when_finished "rm 0001-*" && | |
352 | test_line_count = 1 actual && | |
353 | test_i18ngrep "^Range-diff:$" 0001-* && | |
354 | grep "> 1: .* new message" 0001-* | |
cdc067c3 DS |
355 | ' |
356 | ||
8884cf15 | 357 | test_done |