Merge branch 'jc/ci-upload-artifact-and-linux32'
[git/gitster.git] / t / t3206-range-diff.sh
blob86010931ab6243e0e617b14cae0eb63975edee7d
1 #!/bin/sh
3 test_description='range-diff tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 # Note that because of the range-diff's heuristics, test_commit does more
12 # harm than good. We need some real history.
14 test_expect_success 'setup' '
15 git fast-import <"$TEST_DIRECTORY"/t3206/history.export &&
16 test_oid_cache <<-\EOF
17 # topic
18 t1 sha1:4de457d
19 t2 sha1:fccce22
20 t3 sha1:147e64e
21 t4 sha1:a63e992
22 t1 sha256:b89f8b9
23 t2 sha256:5f12aad
24 t3 sha256:ea8b273
25 t4 sha256:14b7336
27 # unmodified
28 u1 sha1:35b9b25
29 u2 sha1:de345ab
30 u3 sha1:9af6654
31 u4 sha1:2901f77
32 u1 sha256:e3731be
33 u2 sha256:14fadf8
34 u3 sha256:736c4bc
35 u4 sha256:673e77d
37 # topic (abbrev=10)
38 t1_abbrev sha1:4de457d2c0
39 t2_abbrev sha1:fccce22f8c
40 t3_abbrev sha1:147e64ef53
41 t4_abbrev sha1:a63e992599
42 t1_abbrev sha256:b89f8b9092
43 t2_abbrev sha256:5f12aadf34
44 t3_abbrev sha256:ea8b273a6c
45 t4_abbrev sha256:14b73361fc
47 # unmodified (abbrev=10)
48 u1_abbrev sha1:35b9b25f76
49 u2_abbrev sha1:de345ab3de
50 u3_abbrev sha1:9af6654000
51 u4_abbrev sha1:2901f773f3
52 u1_abbrev sha256:e3731be242
53 u2_abbrev sha256:14fadf8cee
54 u3_abbrev sha256:736c4bcb44
55 u4_abbrev sha256:673e77d589
57 # reordered
58 r1 sha1:aca177a
59 r2 sha1:14ad629
60 r3 sha1:ee58208
61 r4 sha1:307b27a
62 r1 sha256:f59d3aa
63 r2 sha256:fb261a8
64 r3 sha256:cb2649b
65 r4 sha256:958577e
67 # removed (deleted)
68 d1 sha1:7657159
69 d2 sha1:43d84d3
70 d3 sha1:a740396
71 d1 sha256:e312513
72 d2 sha256:eb19258
73 d3 sha256:1ccb3c1
75 # added
76 a1 sha1:2716022
77 a2 sha1:b62accd
78 a3 sha1:df46cfa
79 a4 sha1:3e64548
80 a5 sha1:12b4063
81 a1 sha256:d724f4d
82 a2 sha256:1de7762
83 a3 sha256:e159431
84 a4 sha256:b3e483c
85 a5 sha256:90866a7
87 # rebased
88 b1 sha1:cc9c443
89 b2 sha1:c5d9641
90 b3 sha1:28cc2b6
91 b4 sha1:5628ab7
92 b5 sha1:a31b12e
93 b1 sha256:a1a8717
94 b2 sha256:20a5862
95 b3 sha256:587172a
96 b4 sha256:2721c5d
97 b5 sha256:7b57864
99 # changed
100 c1 sha1:a4b3333
101 c2 sha1:f51d370
102 c3 sha1:0559556
103 c4 sha1:d966c5c
104 c1 sha256:f8c2b9d
105 c2 sha256:3fb6318
106 c3 sha256:168ab68
107 c4 sha256:3526539
109 # changed-message
110 m1 sha1:f686024
111 m2 sha1:4ab067d
112 m3 sha1:b9cb956
113 m4 sha1:8add5f1
114 m1 sha256:31e6281
115 m2 sha256:a06bf1b
116 m3 sha256:82dc654
117 m4 sha256:48470c5
119 # renamed
120 n1 sha1:f258d75
121 n2 sha1:017b62d
122 n3 sha1:3ce7af6
123 n4 sha1:1e6226b
124 n1 sha256:ad52114
125 n2 sha256:3b54c8f
126 n3 sha256:3b0a644
127 n4 sha256:e461653
129 # mode change
130 o1 sha1:4d39cb3
131 o2 sha1:26c107f
132 o3 sha1:4c1e0f5
133 o1 sha256:d0dd598
134 o2 sha256:c4a279e
135 o3 sha256:78459d7
137 # added and removed
138 s1 sha1:096b1ba
139 s2 sha1:d92e698
140 s3 sha1:9a1db4d
141 s4 sha1:fea3b5c
142 s1 sha256:a7f9134
143 s2 sha256:b4c2580
144 s3 sha256:1d62aa2
145 s4 sha256:48160e8
147 # Empty delimiter (included so lines match neatly)
148 __ sha1:-------
149 __ sha256:-------
153 test_expect_success 'simple A..B A..C (unmodified)' '
154 git range-diff --no-color main..topic main..unmodified \
155 >actual &&
156 cat >expect <<-EOF &&
157 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
158 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
159 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
160 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
162 test_cmp expect actual
165 test_expect_success 'simple B...C (unmodified)' '
166 git range-diff --no-color topic...unmodified >actual &&
167 # same "expect" as above
168 test_cmp expect actual
171 test_expect_success 'simple A B C (unmodified)' '
172 git range-diff --no-color main topic unmodified >actual &&
173 # same "expect" as above
174 test_cmp expect actual
177 test_expect_success 'simple A..B A..C (unmodified) with --abbrev' '
178 git range-diff --no-color --abbrev=10 main..topic main..unmodified \
179 >actual &&
180 cat >expect <<-EOF &&
181 1: $(test_oid t1_abbrev) = 1: $(test_oid u1_abbrev) s/5/A/
182 2: $(test_oid t2_abbrev) = 2: $(test_oid u2_abbrev) s/4/A/
183 3: $(test_oid t3_abbrev) = 3: $(test_oid u3_abbrev) s/11/B/
184 4: $(test_oid t4_abbrev) = 4: $(test_oid u4_abbrev) s/12/B/
186 test_cmp expect actual
189 test_expect_success 'A^! and A^-<n> (unmodified)' '
190 git range-diff --no-color topic^! unmodified^-1 >actual &&
191 cat >expect <<-EOF &&
192 1: $(test_oid t4) = 1: $(test_oid u4) s/12/B/
194 test_cmp expect actual
197 test_expect_success 'A^{/..} is not mistaken for a range' '
198 test_must_fail git range-diff topic^.. topic^{/..} -- 2>error &&
199 test_grep "not a commit range" error
202 test_expect_success 'trivial reordering' '
203 git range-diff --no-color main topic reordered >actual &&
204 cat >expect <<-EOF &&
205 1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/
206 3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/
207 4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/
208 2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/
210 test_cmp expect actual
213 test_expect_success 'removed a commit' '
214 git range-diff --no-color main topic removed >actual &&
215 cat >expect <<-EOF &&
216 1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/
217 2: $(test_oid t2) < -: $(test_oid __) s/4/A/
218 3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/
219 4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/
221 test_cmp expect actual
224 test_expect_success 'added a commit' '
225 git range-diff --no-color main topic added >actual &&
226 cat >expect <<-EOF &&
227 1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/
228 2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/
229 -: $(test_oid __) > 3: $(test_oid a3) s/6/A/
230 3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/
231 4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/
233 test_cmp expect actual
236 test_expect_success 'new base, A B C' '
237 git range-diff --no-color main topic rebased >actual &&
238 cat >expect <<-EOF &&
239 1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/
240 2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/
241 3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/
242 4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/
244 test_cmp expect actual
247 test_expect_success 'new base, B...C' '
248 # this syntax includes the commits from main!
249 git range-diff --no-color topic...rebased >actual &&
250 cat >expect <<-EOF &&
251 -: $(test_oid __) > 1: $(test_oid b5) unrelated
252 1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/
253 2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/
254 3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/
255 4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/
257 test_cmp expect actual
260 test_expect_success 'changed commit' '
261 git range-diff --no-color topic...changed >actual &&
262 cat >expect <<-EOF &&
263 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
264 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
265 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
266 @@ file: A
271 ++BB
275 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
276 @@ file
277 @@ file: A
281 + BB
286 test_cmp expect actual
289 test_expect_success 'changed commit with --no-patch diff option' '
290 git range-diff --no-color --no-patch topic...changed >actual &&
291 cat >expect <<-EOF &&
292 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
293 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
294 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
295 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
297 test_cmp expect actual
300 test_expect_success 'changed commit with --stat diff option' '
301 git range-diff --no-color --stat topic...changed >actual &&
302 cat >expect <<-EOF &&
303 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
304 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
305 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
306 a => b | 2 +-
307 1 file changed, 1 insertion(+), 1 deletion(-)
308 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
309 a => b | 2 +-
310 1 file changed, 1 insertion(+), 1 deletion(-)
312 test_cmp expect actual
315 test_expect_success 'changed commit with sm config' '
316 git range-diff --no-color --submodule=log topic...changed >actual &&
317 cat >expect <<-EOF &&
318 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
319 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
320 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
321 @@ file: A
326 ++BB
330 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
331 @@ file
332 @@ file: A
336 + BB
341 test_cmp expect actual
344 test_expect_success 'renamed file' '
345 git range-diff --no-color --submodule=log topic...renamed-file >actual &&
346 sed s/Z/\ /g >expect <<-EOF &&
347 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/
348 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/
349 @@ Metadata
350 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
352 Z ## Commit message ##
353 - s/4/A/
354 + s/4/A/ + rename file
356 - ## file ##
357 + ## file => renamed-file ##
361 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/
362 @@ Metadata
363 Z ## Commit message ##
364 Z s/11/B/
366 - ## file ##
367 -@@ file: A
368 + ## renamed-file ##
369 +@@ renamed-file: A
372 Z 10
373 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/
374 @@ Metadata
375 Z ## Commit message ##
376 Z s/12/B/
378 - ## file ##
379 -@@ file: A
380 + ## renamed-file ##
381 +@@ renamed-file: A
383 Z 10
386 test_cmp expect actual
389 test_expect_success 'file with mode only change' '
390 git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
391 sed s/Z/\ /g >expect <<-EOF &&
392 1: $(test_oid t2) ! 1: $(test_oid o1) s/4/A/
393 @@ Metadata
394 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
396 Z ## Commit message ##
397 - s/4/A/
398 + s/4/A/ + add other-file
400 Z ## file ##
402 @@ file
407 + ## other-file (new) ##
408 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/
409 @@ Metadata
410 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
412 Z ## Commit message ##
413 - s/11/B/
414 + s/11/B/ + mode change other-file
416 Z ## file ##
417 Z@@ file: A
418 @@ file: A
419 Z 12
420 Z 13
421 Z 14
423 + ## other-file (mode change 100644 => 100755) ##
424 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/
426 test_cmp expect actual
429 test_expect_success 'file added and later removed' '
430 git range-diff --no-color --submodule=log topic...added-removed >actual &&
431 sed s/Z/\ /g >expect <<-EOF &&
432 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/
433 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/
434 @@ Metadata
435 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
437 Z ## Commit message ##
438 - s/4/A/
439 + s/4/A/ + new-file
441 Z ## file ##
443 @@ file
448 + ## new-file (new) ##
449 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/
450 @@ Metadata
451 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
453 Z ## Commit message ##
454 - s/11/B/
455 + s/11/B/ + remove file
457 Z ## file ##
458 Z@@ file: A
459 @@ file: A
460 Z 12
461 Z 13
462 Z 14
464 + ## new-file (deleted) ##
465 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
467 test_cmp expect actual
470 test_expect_success 'no commits on one side' '
471 git commit --amend -m "new message" &&
472 git range-diff main HEAD@{1} HEAD
475 test_expect_success 'changed message' '
476 git range-diff --no-color topic...changed-message >actual &&
477 sed s/Z/\ /g >expect <<-EOF &&
478 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/
479 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/
480 @@ Metadata
481 Z ## Commit message ##
482 Z s/4/A/
484 + Also a silly comment here!
486 Z ## file ##
489 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
490 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
492 test_cmp expect actual
495 test_expect_success 'dual-coloring' '
496 sed -e "s|^:||" >expect <<-EOF &&
497 :<YELLOW>1: $(test_oid c1) = 1: $(test_oid m1) s/5/A/<RESET>
498 :<RED>2: $(test_oid c2) <RESET><YELLOW>!<RESET><GREEN> 2: $(test_oid m2)<RESET><YELLOW> s/4/A/<RESET>
499 : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
500 : ## Commit message ##<RESET>
501 : s/4/A/<RESET>
502 : <RESET>
503 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
504 : <REVERSE><GREEN>+<RESET>
505 : ## file ##<RESET>
506 : <CYAN> @@<RESET>
507 : 1<RESET>
508 :<RED>3: $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3: $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET>
509 : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
510 : 9<RESET>
511 : 10<RESET>
512 : <RED> -11<RESET>
513 : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
514 : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET>
515 : 12<RESET>
516 : 13<RESET>
517 : 14<RESET>
518 :<RED>4: $(test_oid c4) <RESET><YELLOW>!<RESET><GREEN> 4: $(test_oid m4)<RESET><YELLOW> s/12/B/<RESET>
519 : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
520 : <CYAN> @@ file: A<RESET>
521 : 9<RESET>
522 : 10<RESET>
523 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
524 : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
525 : <RED> -12<RESET>
526 : <GREEN> +B<RESET>
527 : 13<RESET>
529 git range-diff changed...changed-message --color --dual-color >actual.raw &&
530 test_decode_color >actual <actual.raw &&
531 test_cmp expect actual
534 for prev in topic main..topic
536 test_expect_success "format-patch --range-diff=$prev" '
537 test_when_finished "rm -f 000?-*" &&
538 git format-patch --cover-letter --range-diff=$prev \
539 main..unmodified >actual &&
540 test_line_count = 5 actual &&
541 test_grep "^Range-diff:$" 0000-* &&
542 grep "= 1: .* s/5/A" 0000-* &&
543 grep "= 2: .* s/4/A" 0000-* &&
544 grep "= 3: .* s/11/B" 0000-* &&
545 grep "= 4: .* s/12/B" 0000-*
547 done
549 test_expect_success "--range-diff implies --cover-letter for multi-patch series" '
550 test_when_finished "rm -f v2-000?-*" &&
551 git format-patch -v2 --range-diff=topic main..unmodified &&
552 test_grep "^Range-diff against v1:$" v2-0000-cover-letter.patch
555 test_expect_success "explicit --no-cover-letter defeats implied --cover-letter" '
556 test_when_finished "rm -f v2-000?-*" &&
557 test_must_fail git format-patch --no-cover-letter \
558 -v2 --range-diff=topic main..unmodified &&
559 test_must_fail git -c format.coverLetter=no format-patch \
560 -v2 --range-diff=topic main..unmodified
563 test_expect_success 'format-patch --range-diff as commentary' '
564 test_when_finished "rm -f 0001-*" &&
565 git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
566 test_line_count = 1 actual &&
567 test_grep "^Range-diff:$" 0001-* &&
568 grep "> 1: .* new message" 0001-*
571 test_expect_success 'format-patch --range-diff reroll-count with a non-integer' '
572 test_when_finished "rm -f v2.9-0001-*" &&
573 git format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&
574 test_line_count = 1 actual &&
575 test_grep "^Range-diff:$" v2.9-0001-* &&
576 grep "> 1: .* new message" v2.9-0001-*
579 test_expect_success 'format-patch --range-diff reroll-count with a integer' '
580 test_when_finished "rm -f v2-0001-*" &&
581 git format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&
582 test_line_count = 1 actual &&
583 test_grep "^Range-diff ..* v1:$" v2-0001-* &&
584 grep "> 1: .* new message" v2-0001-*
587 test_expect_success 'format-patch --range-diff with v0' '
588 test_when_finished "rm -f v0-0001-*" &&
589 git format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&
590 test_line_count = 1 actual &&
591 test_grep "^Range-diff:$" v0-0001-* &&
592 grep "> 1: .* new message" v0-0001-*
595 test_expect_success 'range-diff overrides diff.noprefix internally' '
596 git -c diff.noprefix=true range-diff HEAD^...
599 test_expect_success 'basic with modified format.pretty with suffix' '
600 git -c format.pretty="format:commit %H%d%n" range-diff \
601 main..topic main..unmodified
604 test_expect_success 'basic with modified format.pretty without "commit "' '
605 git -c format.pretty="format:%H%n" range-diff \
606 main..topic main..unmodified
609 test_expect_success 'range-diff compares notes by default' '
610 test_when_finished "git notes remove topic unmodified || :" &&
611 git notes add -m "topic note" topic &&
612 git notes add -m "unmodified note" unmodified &&
613 git range-diff --no-color main..topic main..unmodified \
614 >actual &&
615 sed s/Z/\ /g >expect <<-EOF &&
616 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
617 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
618 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
619 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
620 @@ Commit message
623 Z ## Notes ##
624 - topic note
625 + unmodified note
627 Z ## file ##
628 Z@@ file: A
630 test_cmp expect actual
633 test_expect_success 'range-diff with --no-notes' '
634 test_when_finished "git notes remove topic unmodified || :" &&
635 git notes add -m "topic note" topic &&
636 git notes add -m "unmodified note" unmodified &&
637 git range-diff --no-color --no-notes main..topic main..unmodified \
638 >actual &&
639 cat >expect <<-EOF &&
640 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
641 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
642 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
643 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
645 test_cmp expect actual
648 test_expect_success 'range-diff with multiple --notes' '
649 test_when_finished "git notes --ref=note1 remove topic unmodified || :" &&
650 git notes --ref=note1 add -m "topic note1" topic &&
651 git notes --ref=note1 add -m "unmodified note1" unmodified &&
652 test_when_finished "git notes --ref=note2 remove topic unmodified || :" &&
653 git notes --ref=note2 add -m "topic note2" topic &&
654 git notes --ref=note2 add -m "unmodified note2" unmodified &&
655 git range-diff --no-color --notes=note1 --notes=note2 main..topic main..unmodified \
656 >actual &&
657 sed s/Z/\ /g >expect <<-EOF &&
658 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
659 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
660 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
661 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
662 @@ Commit message
665 Z ## Notes (note1) ##
666 - topic note1
667 + unmodified note1
670 Z ## Notes (note2) ##
671 - topic note2
672 + unmodified note2
674 Z ## file ##
675 Z@@ file: A
677 test_cmp expect actual
680 # `range-diff` should act like `log` with regards to notes
681 test_expect_success 'range-diff with --notes=custom does not show default notes' '
682 test_when_finished "git notes remove topic unmodified || :" &&
683 git notes add -m "topic note" topic &&
684 git notes add -m "unmodified note" unmodified &&
685 test_when_finished "git notes --ref=custom remove topic unmodified || :" &&
686 git notes --ref=custom add -m "topic note" topic &&
687 git notes --ref=custom add -m "unmodified note" unmodified &&
688 git range-diff --notes=custom main..topic main..unmodified \
689 >actual &&
690 ! grep "## Notes ##" actual &&
691 grep "## Notes (custom) ##" actual
694 test_expect_success 'format-patch --range-diff does not compare notes by default' '
695 test_when_finished "git notes remove topic unmodified || :" &&
696 git notes add -m "topic note" topic &&
697 git notes add -m "unmodified note" unmodified &&
698 test_when_finished "rm -f 000?-*" &&
699 git format-patch --cover-letter --range-diff=$prev \
700 main..unmodified >actual &&
701 test_line_count = 5 actual &&
702 test_grep "^Range-diff:$" 0000-* &&
703 grep "= 1: .* s/5/A" 0000-* &&
704 grep "= 2: .* s/4/A" 0000-* &&
705 grep "= 3: .* s/11/B" 0000-* &&
706 grep "= 4: .* s/12/B" 0000-* &&
707 ! grep "Notes" 0000-* &&
708 ! grep "note" 0000-*
711 test_expect_success 'format-patch --notes=custom --range-diff only compares custom notes' '
712 test_when_finished "git notes remove topic unmodified || :" &&
713 git notes add -m "topic note" topic &&
714 git notes add -m "unmodified note" unmodified &&
715 test_when_finished "git notes --ref=custom remove topic unmodified || :" &&
716 git notes --ref=custom add -m "topic note (custom)" topic &&
717 git notes --ref=custom add -m "unmodified note (custom)" unmodified &&
718 test_when_finished "rm -f 000?-*" &&
719 git format-patch --notes=custom --cover-letter --range-diff=$prev \
720 main..unmodified >actual &&
721 grep "## Notes (custom) ##" 0000-* &&
722 ! grep "## Notes ##" 0000-*
725 test_expect_success 'format-patch --range-diff with --no-notes' '
726 test_when_finished "git notes remove topic unmodified || :" &&
727 git notes add -m "topic note" topic &&
728 git notes add -m "unmodified note" unmodified &&
729 test_when_finished "rm -f 000?-*" &&
730 git format-patch --no-notes --cover-letter --range-diff=$prev \
731 main..unmodified >actual &&
732 test_line_count = 5 actual &&
733 test_grep "^Range-diff:$" 0000-* &&
734 grep "= 1: .* s/5/A" 0000-* &&
735 grep "= 2: .* s/4/A" 0000-* &&
736 grep "= 3: .* s/11/B" 0000-* &&
737 grep "= 4: .* s/12/B" 0000-* &&
738 ! grep "Notes" 0000-* &&
739 ! grep "note" 0000-*
742 test_expect_success 'format-patch --range-diff with --notes' '
743 test_when_finished "git notes remove topic unmodified || :" &&
744 git notes add -m "topic note" topic &&
745 git notes add -m "unmodified note" unmodified &&
746 test_when_finished "rm -f 000?-*" &&
747 git format-patch --notes --cover-letter --range-diff=$prev \
748 main..unmodified >actual &&
749 test_line_count = 5 actual &&
750 test_grep "^Range-diff:$" 0000-* &&
751 grep "= 1: .* s/5/A" 0000-* &&
752 grep "= 2: .* s/4/A" 0000-* &&
753 grep "= 3: .* s/11/B" 0000-* &&
754 grep "! 4: .* s/12/B" 0000-* &&
755 sed s/Z/\ /g >expect <<-EOF &&
756 @@ Commit message
759 Z ## Notes ##
760 - topic note
761 + unmodified note
763 Z ## file ##
764 Z@@ file: A
766 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
767 test_cmp expect actual
770 test_expect_success 'format-patch --range-diff with format.notes config' '
771 test_when_finished "git notes remove topic unmodified || :" &&
772 git notes add -m "topic note" topic &&
773 git notes add -m "unmodified note" unmodified &&
774 test_config format.notes true &&
775 test_when_finished "rm -f 000?-*" &&
776 git format-patch --cover-letter --range-diff=$prev \
777 main..unmodified >actual &&
778 test_line_count = 5 actual &&
779 test_grep "^Range-diff:$" 0000-* &&
780 grep "= 1: .* s/5/A" 0000-* &&
781 grep "= 2: .* s/4/A" 0000-* &&
782 grep "= 3: .* s/11/B" 0000-* &&
783 grep "! 4: .* s/12/B" 0000-* &&
784 sed s/Z/\ /g >expect <<-EOF &&
785 @@ Commit message
788 Z ## Notes ##
789 - topic note
790 + unmodified note
792 Z ## file ##
793 Z@@ file: A
795 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
796 test_cmp expect actual
799 test_expect_success 'format-patch --range-diff with multiple notes' '
800 test_when_finished "git notes --ref=note1 remove topic unmodified || :" &&
801 git notes --ref=note1 add -m "topic note1" topic &&
802 git notes --ref=note1 add -m "unmodified note1" unmodified &&
803 test_when_finished "git notes --ref=note2 remove topic unmodified || :" &&
804 git notes --ref=note2 add -m "topic note2" topic &&
805 git notes --ref=note2 add -m "unmodified note2" unmodified &&
806 test_when_finished "rm -f 000?-*" &&
807 git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
808 main..unmodified >actual &&
809 test_line_count = 5 actual &&
810 test_grep "^Range-diff:$" 0000-* &&
811 grep "= 1: .* s/5/A" 0000-* &&
812 grep "= 2: .* s/4/A" 0000-* &&
813 grep "= 3: .* s/11/B" 0000-* &&
814 grep "! 4: .* s/12/B" 0000-* &&
815 sed s/Z/\ /g >expect <<-EOF &&
816 @@ Commit message
819 Z ## Notes (note1) ##
820 - topic note1
821 + unmodified note1
824 Z ## Notes (note2) ##
825 - topic note2
826 + unmodified note2
828 Z ## file ##
829 Z@@ file: A
831 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
832 test_cmp expect actual
835 test_expect_success '--left-only/--right-only' '
836 git switch --orphan left-right &&
837 test_commit first &&
838 test_commit unmatched &&
839 test_commit common &&
840 git switch -C left-right first &&
841 git cherry-pick common &&
843 git range-diff -s --left-only ...common >actual &&
844 head_oid=$(git rev-parse --short HEAD) &&
845 common_oid=$(git rev-parse --short common) &&
846 echo "1: $head_oid = 2: $common_oid common" >expect &&
847 test_cmp expect actual
850 test_expect_success 'ranges with pathspecs' '
851 git range-diff topic...mode-only-change -- other-file >actual &&
852 test_line_count = 2 actual &&
853 topic_oid=$(git rev-parse --short topic) &&
854 mode_change_oid=$(git rev-parse --short mode-only-change^) &&
855 file_change_oid=$(git rev-parse --short mode-only-change) &&
856 grep "$mode_change_oid" actual &&
857 ! grep "$file_change_oid" actual &&
858 ! grep "$topic_oid" actual
861 test_expect_success 'submodule changes are shown irrespective of diff.submodule' '
862 git init sub-repo &&
863 test_commit -C sub-repo sub-first &&
864 sub_oid1=$(git -C sub-repo rev-parse HEAD) &&
865 test_commit -C sub-repo sub-second &&
866 sub_oid2=$(git -C sub-repo rev-parse HEAD) &&
867 test_commit -C sub-repo sub-third &&
868 sub_oid3=$(git -C sub-repo rev-parse HEAD) &&
870 git checkout -b main-sub topic &&
871 git -c protocol.file.allow=always submodule add ./sub-repo sub &&
872 git -C sub checkout --detach sub-first &&
873 git commit -m "add sub" sub &&
874 sup_oid1=$(git rev-parse --short HEAD) &&
875 git checkout -b topic-sub &&
876 git -C sub checkout sub-second &&
877 git commit -m "change sub" sub &&
878 sup_oid2=$(git rev-parse --short HEAD) &&
879 git checkout -b modified-sub main-sub &&
880 git -C sub checkout sub-third &&
881 git commit -m "change sub" sub &&
882 sup_oid3=$(git rev-parse --short HEAD) &&
883 sup_oid0=$(test_oid __) &&
885 test_config diff.submodule log &&
886 git range-diff topic topic-sub modified-sub >actual &&
887 cat >expect <<-EOF &&
888 1: $sup_oid1 = 1: $sup_oid1 add sub
889 2: $sup_oid2 < -: $sup_oid0 change sub
890 -: $sup_oid0 > 2: $sup_oid3 change sub
892 test_cmp expect actual &&
893 test_config diff.submodule diff &&
894 git range-diff topic topic-sub modified-sub >actual &&
895 git range-diff --creation-factor=100 topic topic-sub modified-sub >actual &&
896 cat >expect <<-EOF &&
897 1: $sup_oid1 = 1: $sup_oid1 add sub
898 2: $sup_oid2 ! 2: $sup_oid3 change sub
899 @@ Commit message
900 ## sub ##
902 -Subproject commit $sub_oid1
903 -+Subproject commit $sub_oid2
904 ++Subproject commit $sub_oid3
906 test_cmp expect actual &&
907 test_config diff.submodule diff &&
908 git range-diff --creation-factor=100 topic topic-sub modified-sub >actual &&
909 test_cmp expect actual
912 test_done