dir: exit before wildcard fall-through if there is no wildcard
[git/raj.git] / t / t3206-range-diff.sh
blob0579cd996976a60db41a7d90d1cd833773f445a3
1 #!/bin/sh
3 test_description='range-diff tests'
5 . ./test-lib.sh
7 # Note that because of the range-diff's heuristics, test_commit does more
8 # harm than good. We need some real history.
10 test_expect_success 'setup' '
11 git fast-import < "$TEST_DIRECTORY"/t3206/history.export &&
12 test_oid_cache <<-EOF
13 # topic
14 t1 sha1:4de457d
15 t2 sha1:fccce22
16 t3 sha1:147e64e
17 t4 sha1:a63e992
18 t1 sha256:b89f8b9
19 t2 sha256:5f12aad
20 t3 sha256:ea8b273
21 t4 sha256:14b7336
23 # unmodified
24 u1 sha1:35b9b25
25 u2 sha1:de345ab
26 u3 sha1:9af6654
27 u4 sha1:2901f77
28 u1 sha256:e3731be
29 u2 sha256:14fadf8
30 u3 sha256:736c4bc
31 u4 sha256:673e77d
33 # reordered
34 r1 sha1:aca177a
35 r2 sha1:14ad629
36 r3 sha1:ee58208
37 r4 sha1:307b27a
38 r1 sha256:f59d3aa
39 r2 sha256:fb261a8
40 r3 sha256:cb2649b
41 r4 sha256:958577e
43 # removed (deleted)
44 d1 sha1:7657159
45 d2 sha1:43d84d3
46 d3 sha1:a740396
47 d1 sha256:e312513
48 d2 sha256:eb19258
49 d3 sha256:1ccb3c1
51 # added
52 a1 sha1:2716022
53 a2 sha1:b62accd
54 a3 sha1:df46cfa
55 a4 sha1:3e64548
56 a5 sha1:12b4063
57 a1 sha256:d724f4d
58 a2 sha256:1de7762
59 a3 sha256:e159431
60 a4 sha256:b3e483c
61 a5 sha256:90866a7
63 # rebased
64 b1 sha1:cc9c443
65 b2 sha1:c5d9641
66 b3 sha1:28cc2b6
67 b4 sha1:5628ab7
68 b5 sha1:a31b12e
69 b1 sha256:a1a8717
70 b2 sha256:20a5862
71 b3 sha256:587172a
72 b4 sha256:2721c5d
73 b5 sha256:7b57864
75 # changed
76 c1 sha1:a4b3333
77 c2 sha1:f51d370
78 c3 sha1:0559556
79 c4 sha1:d966c5c
80 c1 sha256:f8c2b9d
81 c2 sha256:3fb6318
82 c3 sha256:168ab68
83 c4 sha256:3526539
85 # changed-message
86 m1 sha1:f686024
87 m2 sha1:4ab067d
88 m3 sha1:b9cb956
89 m4 sha1:8add5f1
90 m1 sha256:31e6281
91 m2 sha256:a06bf1b
92 m3 sha256:82dc654
93 m4 sha256:48470c5
95 # renamed
96 n1 sha1:f258d75
97 n2 sha1:017b62d
98 n3 sha1:3ce7af6
99 n4 sha1:1e6226b
100 n1 sha256:ad52114
101 n2 sha256:3b54c8f
102 n3 sha256:3b0a644
103 n4 sha256:e461653
105 # added and removed
106 s1 sha1:096b1ba
107 s2 sha1:d92e698
108 s3 sha1:9a1db4d
109 s4 sha1:fea3b5c
110 s1 sha256:a7f9134
111 s2 sha256:b4c2580
112 s3 sha256:1d62aa2
113 s4 sha256:48160e8
115 # Empty delimiter (included so lines match neatly)
116 __ sha1:-------
117 __ sha256:-------
121 test_expect_success 'simple A..B A..C (unmodified)' '
122 git range-diff --no-color master..topic master..unmodified \
123 >actual &&
124 cat >expected <<-EOF &&
125 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
126 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
127 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
128 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
130 test_cmp expected actual
133 test_expect_success 'simple B...C (unmodified)' '
134 git range-diff --no-color topic...unmodified >actual &&
135 # same "expected" as above
136 test_cmp expected actual
139 test_expect_success 'simple A B C (unmodified)' '
140 git range-diff --no-color master topic unmodified >actual &&
141 # same "expected" as above
142 test_cmp expected actual
145 test_expect_success 'trivial reordering' '
146 git range-diff --no-color master topic reordered >actual &&
147 cat >expected <<-EOF &&
148 1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/
149 3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/
150 4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/
151 2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/
153 test_cmp expected actual
156 test_expect_success 'removed a commit' '
157 git range-diff --no-color master topic removed >actual &&
158 cat >expected <<-EOF &&
159 1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/
160 2: $(test_oid t2) < -: $(test_oid __) s/4/A/
161 3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/
162 4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/
164 test_cmp expected actual
167 test_expect_success 'added a commit' '
168 git range-diff --no-color master topic added >actual &&
169 cat >expected <<-EOF &&
170 1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/
171 2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/
172 -: $(test_oid __) > 3: $(test_oid a3) s/6/A/
173 3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/
174 4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/
176 test_cmp expected actual
179 test_expect_success 'new base, A B C' '
180 git range-diff --no-color master topic rebased >actual &&
181 cat >expected <<-EOF &&
182 1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/
183 2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/
184 3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/
185 4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/
187 test_cmp expected actual
190 test_expect_success 'new base, B...C' '
191 # this syntax includes the commits from master!
192 git range-diff --no-color topic...rebased >actual &&
193 cat >expected <<-EOF &&
194 -: $(test_oid __) > 1: $(test_oid b5) unrelated
195 1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/
196 2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/
197 3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/
198 4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/
200 test_cmp expected actual
203 test_expect_success 'changed commit' '
204 git range-diff --no-color topic...changed >actual &&
205 cat >expected <<-EOF &&
206 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
207 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
208 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
209 @@ file: A
214 ++BB
218 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
219 @@ file
220 @@ file: A
224 + BB
229 test_cmp expected actual
232 test_expect_success 'changed commit with --no-patch diff option' '
233 git range-diff --no-color --no-patch topic...changed >actual &&
234 cat >expected <<-EOF &&
235 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
236 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
237 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
238 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
240 test_cmp expected actual
243 test_expect_success 'changed commit with --stat diff option' '
244 git range-diff --no-color --stat topic...changed >actual &&
245 cat >expected <<-EOF &&
246 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
247 a => b | 0
248 1 file changed, 0 insertions(+), 0 deletions(-)
249 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
250 a => b | 0
251 1 file changed, 0 insertions(+), 0 deletions(-)
252 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
253 a => b | 0
254 1 file changed, 0 insertions(+), 0 deletions(-)
255 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
256 a => b | 0
257 1 file changed, 0 insertions(+), 0 deletions(-)
259 test_cmp expected actual
262 test_expect_success 'changed commit with sm config' '
263 git range-diff --no-color --submodule=log topic...changed >actual &&
264 cat >expected <<-EOF &&
265 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
266 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
267 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
268 @@ file: A
273 ++BB
277 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
278 @@ file
279 @@ file: A
283 + BB
288 test_cmp expected actual
291 test_expect_success 'renamed file' '
292 git range-diff --no-color --submodule=log topic...renamed-file >actual &&
293 sed s/Z/\ /g >expected <<-EOF &&
294 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/
295 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/
296 @@ Metadata
297 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
299 Z ## Commit message ##
300 - s/4/A/
301 + s/4/A/ + rename file
303 - ## file ##
304 + ## file => renamed-file ##
308 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/
309 @@ Metadata
310 Z ## Commit message ##
311 Z s/11/B/
313 - ## file ##
314 -@@ file: A
315 + ## renamed-file ##
316 +@@ renamed-file: A
319 Z 10
320 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/
321 @@ Metadata
322 Z ## Commit message ##
323 Z s/12/B/
325 - ## file ##
326 -@@ file: A
327 + ## renamed-file ##
328 +@@ renamed-file: A
330 Z 10
333 test_cmp expected actual
336 test_expect_success 'file with mode only change' '
337 git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
338 sed s/Z/\ /g >expected <<-EOF &&
339 1: fccce22 ! 1: 4d39cb3 s/4/A/
340 @@ Metadata
341 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
343 Z ## Commit message ##
344 - s/4/A/
345 + s/4/A/ + add other-file
347 Z ## file ##
349 @@ file
354 + ## other-file (new) ##
355 2: 147e64e ! 2: 26c107f s/11/B/
356 @@ Metadata
357 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
359 Z ## Commit message ##
360 - s/11/B/
361 + s/11/B/ + mode change other-file
363 Z ## file ##
364 Z@@ file: A
365 @@ file: A
366 Z 12
367 Z 13
368 Z 14
370 + ## other-file (mode change 100644 => 100755) ##
371 3: a63e992 = 3: 4c1e0f5 s/12/B/
373 test_cmp expected actual
376 test_expect_success 'file added and later removed' '
377 git range-diff --no-color --submodule=log topic...added-removed >actual &&
378 sed s/Z/\ /g >expected <<-EOF &&
379 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/
380 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/
381 @@ Metadata
382 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
384 Z ## Commit message ##
385 - s/4/A/
386 + s/4/A/ + new-file
388 Z ## file ##
390 @@ file
395 + ## new-file (new) ##
396 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/
397 @@ Metadata
398 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
400 Z ## Commit message ##
401 - s/11/B/
402 + s/11/B/ + remove file
404 Z ## file ##
405 Z@@ file: A
406 @@ file: A
407 Z 12
408 Z 13
409 Z 14
411 + ## new-file (deleted) ##
412 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
414 test_cmp expected actual
417 test_expect_success 'no commits on one side' '
418 git commit --amend -m "new message" &&
419 git range-diff master HEAD@{1} HEAD
422 test_expect_success 'changed message' '
423 git range-diff --no-color topic...changed-message >actual &&
424 sed s/Z/\ /g >expected <<-EOF &&
425 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/
426 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/
427 @@ Metadata
428 Z ## Commit message ##
429 Z s/4/A/
431 + Also a silly comment here!
433 Z ## file ##
436 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
437 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
439 test_cmp expected actual
442 test_expect_success 'dual-coloring' '
443 sed -e "s|^:||" >expect <<-EOF &&
444 :<YELLOW>1: $(test_oid c1) = 1: $(test_oid m1) s/5/A/<RESET>
445 :<RED>2: $(test_oid c2) <RESET><YELLOW>!<RESET><GREEN> 2: $(test_oid m2)<RESET><YELLOW> s/4/A/<RESET>
446 : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
447 : ## Commit message ##<RESET>
448 : s/4/A/<RESET>
449 : <RESET>
450 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
451 : <REVERSE><GREEN>+<RESET>
452 : ## file ##<RESET>
453 : <CYAN> @@<RESET>
454 : 1<RESET>
455 :<RED>3: $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3: $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET>
456 : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
457 : 9<RESET>
458 : 10<RESET>
459 : <RED> -11<RESET>
460 : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
461 : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET>
462 : 12<RESET>
463 : 13<RESET>
464 : 14<RESET>
465 :<RED>4: $(test_oid c4) <RESET><YELLOW>!<RESET><GREEN> 4: $(test_oid m4)<RESET><YELLOW> s/12/B/<RESET>
466 : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
467 : <CYAN> @@ file: A<RESET>
468 : 9<RESET>
469 : 10<RESET>
470 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
471 : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
472 : <RED> -12<RESET>
473 : <GREEN> +B<RESET>
474 : 13<RESET>
476 git range-diff changed...changed-message --color --dual-color >actual.raw &&
477 test_decode_color >actual <actual.raw &&
478 test_cmp expect actual
481 for prev in topic master..topic
483 test_expect_success "format-patch --range-diff=$prev" '
484 git format-patch --cover-letter --range-diff=$prev \
485 master..unmodified >actual &&
486 test_when_finished "rm 000?-*" &&
487 test_line_count = 5 actual &&
488 test_i18ngrep "^Range-diff:$" 0000-* &&
489 grep "= 1: .* s/5/A" 0000-* &&
490 grep "= 2: .* s/4/A" 0000-* &&
491 grep "= 3: .* s/11/B" 0000-* &&
492 grep "= 4: .* s/12/B" 0000-*
494 done
496 test_expect_success 'format-patch --range-diff as commentary' '
497 git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
498 test_when_finished "rm 0001-*" &&
499 test_line_count = 1 actual &&
500 test_i18ngrep "^Range-diff:$" 0001-* &&
501 grep "> 1: .* new message" 0001-*
504 test_expect_success 'range-diff overrides diff.noprefix internally' '
505 git -c diff.noprefix=true range-diff HEAD^...
508 test_done