]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3206-range-diff.sh
Merge branch 'jt/clone-unborn-head'
[thirdparty/git.git] / t / t3206-range-diff.sh
1 #!/bin/sh
2
3 test_description='range-diff tests'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 # Note that because of the range-diff's heuristics, test_commit does more
11 # harm than good. We need some real history.
12
13 test_expect_success 'setup' '
14 git fast-import <"$TEST_DIRECTORY"/t3206/history.export &&
15 test_oid_cache <<-\EOF
16 # topic
17 t1 sha1:4de457d
18 t2 sha1:fccce22
19 t3 sha1:147e64e
20 t4 sha1:a63e992
21 t1 sha256:b89f8b9
22 t2 sha256:5f12aad
23 t3 sha256:ea8b273
24 t4 sha256:14b7336
25
26 # unmodified
27 u1 sha1:35b9b25
28 u2 sha1:de345ab
29 u3 sha1:9af6654
30 u4 sha1:2901f77
31 u1 sha256:e3731be
32 u2 sha256:14fadf8
33 u3 sha256:736c4bc
34 u4 sha256:673e77d
35
36 # reordered
37 r1 sha1:aca177a
38 r2 sha1:14ad629
39 r3 sha1:ee58208
40 r4 sha1:307b27a
41 r1 sha256:f59d3aa
42 r2 sha256:fb261a8
43 r3 sha256:cb2649b
44 r4 sha256:958577e
45
46 # removed (deleted)
47 d1 sha1:7657159
48 d2 sha1:43d84d3
49 d3 sha1:a740396
50 d1 sha256:e312513
51 d2 sha256:eb19258
52 d3 sha256:1ccb3c1
53
54 # added
55 a1 sha1:2716022
56 a2 sha1:b62accd
57 a3 sha1:df46cfa
58 a4 sha1:3e64548
59 a5 sha1:12b4063
60 a1 sha256:d724f4d
61 a2 sha256:1de7762
62 a3 sha256:e159431
63 a4 sha256:b3e483c
64 a5 sha256:90866a7
65
66 # rebased
67 b1 sha1:cc9c443
68 b2 sha1:c5d9641
69 b3 sha1:28cc2b6
70 b4 sha1:5628ab7
71 b5 sha1:a31b12e
72 b1 sha256:a1a8717
73 b2 sha256:20a5862
74 b3 sha256:587172a
75 b4 sha256:2721c5d
76 b5 sha256:7b57864
77
78 # changed
79 c1 sha1:a4b3333
80 c2 sha1:f51d370
81 c3 sha1:0559556
82 c4 sha1:d966c5c
83 c1 sha256:f8c2b9d
84 c2 sha256:3fb6318
85 c3 sha256:168ab68
86 c4 sha256:3526539
87
88 # changed-message
89 m1 sha1:f686024
90 m2 sha1:4ab067d
91 m3 sha1:b9cb956
92 m4 sha1:8add5f1
93 m1 sha256:31e6281
94 m2 sha256:a06bf1b
95 m3 sha256:82dc654
96 m4 sha256:48470c5
97
98 # renamed
99 n1 sha1:f258d75
100 n2 sha1:017b62d
101 n3 sha1:3ce7af6
102 n4 sha1:1e6226b
103 n1 sha256:ad52114
104 n2 sha256:3b54c8f
105 n3 sha256:3b0a644
106 n4 sha256:e461653
107
108 # mode change
109 o1 sha1:4d39cb3
110 o2 sha1:26c107f
111 o3 sha1:4c1e0f5
112 o1 sha256:d0dd598
113 o2 sha256:c4a279e
114 o3 sha256:78459d7
115
116 # added and removed
117 s1 sha1:096b1ba
118 s2 sha1:d92e698
119 s3 sha1:9a1db4d
120 s4 sha1:fea3b5c
121 s1 sha256:a7f9134
122 s2 sha256:b4c2580
123 s3 sha256:1d62aa2
124 s4 sha256:48160e8
125
126 # Empty delimiter (included so lines match neatly)
127 __ sha1:-------
128 __ sha256:-------
129 EOF
130 '
131
132 test_expect_success 'simple A..B A..C (unmodified)' '
133 git range-diff --no-color main..topic main..unmodified \
134 >actual &&
135 cat >expect <<-EOF &&
136 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
137 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
138 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
139 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
140 EOF
141 test_cmp expect actual
142 '
143
144 test_expect_success 'simple B...C (unmodified)' '
145 git range-diff --no-color topic...unmodified >actual &&
146 # same "expect" as above
147 test_cmp expect actual
148 '
149
150 test_expect_success 'simple A B C (unmodified)' '
151 git range-diff --no-color main topic unmodified >actual &&
152 # same "expect" as above
153 test_cmp expect actual
154 '
155
156 test_expect_success 'trivial reordering' '
157 git range-diff --no-color main topic reordered >actual &&
158 cat >expect <<-EOF &&
159 1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/
160 3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/
161 4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/
162 2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/
163 EOF
164 test_cmp expect actual
165 '
166
167 test_expect_success 'removed a commit' '
168 git range-diff --no-color main topic removed >actual &&
169 cat >expect <<-EOF &&
170 1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/
171 2: $(test_oid t2) < -: $(test_oid __) s/4/A/
172 3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/
173 4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/
174 EOF
175 test_cmp expect actual
176 '
177
178 test_expect_success 'added a commit' '
179 git range-diff --no-color main topic added >actual &&
180 cat >expect <<-EOF &&
181 1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/
182 2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/
183 -: $(test_oid __) > 3: $(test_oid a3) s/6/A/
184 3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/
185 4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/
186 EOF
187 test_cmp expect actual
188 '
189
190 test_expect_success 'new base, A B C' '
191 git range-diff --no-color main topic rebased >actual &&
192 cat >expect <<-EOF &&
193 1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/
194 2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/
195 3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/
196 4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/
197 EOF
198 test_cmp expect actual
199 '
200
201 test_expect_success 'new base, B...C' '
202 # this syntax includes the commits from main!
203 git range-diff --no-color topic...rebased >actual &&
204 cat >expect <<-EOF &&
205 -: $(test_oid __) > 1: $(test_oid b5) unrelated
206 1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/
207 2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/
208 3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/
209 4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/
210 EOF
211 test_cmp expect actual
212 '
213
214 test_expect_success 'changed commit' '
215 git range-diff --no-color topic...changed >actual &&
216 cat >expect <<-EOF &&
217 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
218 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
219 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
220 @@ file: A
221 9
222 10
223 -11
224 -+B
225 ++BB
226 12
227 13
228 14
229 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
230 @@ file
231 @@ file: A
232 9
233 10
234 - B
235 + BB
236 -12
237 +B
238 13
239 EOF
240 test_cmp expect actual
241 '
242
243 test_expect_success 'changed commit with --no-patch diff option' '
244 git range-diff --no-color --no-patch topic...changed >actual &&
245 cat >expect <<-EOF &&
246 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
247 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
248 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
249 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
250 EOF
251 test_cmp expect actual
252 '
253
254 test_expect_success 'changed commit with --stat diff option' '
255 git range-diff --no-color --stat topic...changed >actual &&
256 cat >expect <<-EOF &&
257 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
258 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
259 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
260 a => b | 2 +-
261 1 file changed, 1 insertion(+), 1 deletion(-)
262 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
263 a => b | 2 +-
264 1 file changed, 1 insertion(+), 1 deletion(-)
265 EOF
266 test_cmp expect actual
267 '
268
269 test_expect_success 'changed commit with sm config' '
270 git range-diff --no-color --submodule=log topic...changed >actual &&
271 cat >expect <<-EOF &&
272 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
273 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
274 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
275 @@ file: A
276 9
277 10
278 -11
279 -+B
280 ++BB
281 12
282 13
283 14
284 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
285 @@ file
286 @@ file: A
287 9
288 10
289 - B
290 + BB
291 -12
292 +B
293 13
294 EOF
295 test_cmp expect actual
296 '
297
298 test_expect_success 'renamed file' '
299 git range-diff --no-color --submodule=log topic...renamed-file >actual &&
300 sed s/Z/\ /g >expect <<-EOF &&
301 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/
302 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/
303 @@ Metadata
304 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
305 Z
306 Z ## Commit message ##
307 - s/4/A/
308 + s/4/A/ + rename file
309 Z
310 - ## file ##
311 + ## file => renamed-file ##
312 Z@@
313 Z 1
314 Z 2
315 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/
316 @@ Metadata
317 Z ## Commit message ##
318 Z s/11/B/
319 Z
320 - ## file ##
321 -@@ file: A
322 + ## renamed-file ##
323 +@@ renamed-file: A
324 Z 8
325 Z 9
326 Z 10
327 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/
328 @@ Metadata
329 Z ## Commit message ##
330 Z s/12/B/
331 Z
332 - ## file ##
333 -@@ file: A
334 + ## renamed-file ##
335 +@@ renamed-file: A
336 Z 9
337 Z 10
338 Z B
339 EOF
340 test_cmp expect actual
341 '
342
343 test_expect_success 'file with mode only change' '
344 git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
345 sed s/Z/\ /g >expect <<-EOF &&
346 1: $(test_oid t2) ! 1: $(test_oid o1) s/4/A/
347 @@ Metadata
348 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
349 Z
350 Z ## Commit message ##
351 - s/4/A/
352 + s/4/A/ + add other-file
353 Z
354 Z ## file ##
355 Z@@
356 @@ file
357 Z A
358 Z 6
359 Z 7
360 +
361 + ## other-file (new) ##
362 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/
363 @@ Metadata
364 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
365 Z
366 Z ## Commit message ##
367 - s/11/B/
368 + s/11/B/ + mode change other-file
369 Z
370 Z ## file ##
371 Z@@ file: A
372 @@ file: A
373 Z 12
374 Z 13
375 Z 14
376 +
377 + ## other-file (mode change 100644 => 100755) ##
378 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/
379 EOF
380 test_cmp expect actual
381 '
382
383 test_expect_success 'file added and later removed' '
384 git range-diff --no-color --submodule=log topic...added-removed >actual &&
385 sed s/Z/\ /g >expect <<-EOF &&
386 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/
387 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/
388 @@ Metadata
389 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
390 Z
391 Z ## Commit message ##
392 - s/4/A/
393 + s/4/A/ + new-file
394 Z
395 Z ## file ##
396 Z@@
397 @@ file
398 Z A
399 Z 6
400 Z 7
401 +
402 + ## new-file (new) ##
403 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/
404 @@ Metadata
405 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
406 Z
407 Z ## Commit message ##
408 - s/11/B/
409 + s/11/B/ + remove file
410 Z
411 Z ## file ##
412 Z@@ file: A
413 @@ file: A
414 Z 12
415 Z 13
416 Z 14
417 +
418 + ## new-file (deleted) ##
419 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
420 EOF
421 test_cmp expect actual
422 '
423
424 test_expect_success 'no commits on one side' '
425 git commit --amend -m "new message" &&
426 git range-diff main HEAD@{1} HEAD
427 '
428
429 test_expect_success 'changed message' '
430 git range-diff --no-color topic...changed-message >actual &&
431 sed s/Z/\ /g >expect <<-EOF &&
432 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/
433 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/
434 @@ Metadata
435 Z ## Commit message ##
436 Z s/4/A/
437 Z
438 + Also a silly comment here!
439 +
440 Z ## file ##
441 Z@@
442 Z 1
443 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
444 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
445 EOF
446 test_cmp expect actual
447 '
448
449 test_expect_success 'dual-coloring' '
450 sed -e "s|^:||" >expect <<-EOF &&
451 :<YELLOW>1: $(test_oid c1) = 1: $(test_oid m1) s/5/A/<RESET>
452 :<RED>2: $(test_oid c2) <RESET><YELLOW>!<RESET><GREEN> 2: $(test_oid m2)<RESET><YELLOW> s/4/A/<RESET>
453 : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
454 : ## Commit message ##<RESET>
455 : s/4/A/<RESET>
456 : <RESET>
457 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
458 : <REVERSE><GREEN>+<RESET>
459 : ## file ##<RESET>
460 : <CYAN> @@<RESET>
461 : 1<RESET>
462 :<RED>3: $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3: $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET>
463 : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
464 : 9<RESET>
465 : 10<RESET>
466 : <RED> -11<RESET>
467 : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
468 : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET>
469 : 12<RESET>
470 : 13<RESET>
471 : 14<RESET>
472 :<RED>4: $(test_oid c4) <RESET><YELLOW>!<RESET><GREEN> 4: $(test_oid m4)<RESET><YELLOW> s/12/B/<RESET>
473 : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
474 : <CYAN> @@ file: A<RESET>
475 : 9<RESET>
476 : 10<RESET>
477 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
478 : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
479 : <RED> -12<RESET>
480 : <GREEN> +B<RESET>
481 : 13<RESET>
482 EOF
483 git range-diff changed...changed-message --color --dual-color >actual.raw &&
484 test_decode_color >actual <actual.raw &&
485 test_cmp expect actual
486 '
487
488 for prev in topic main..topic
489 do
490 test_expect_success "format-patch --range-diff=$prev" '
491 git format-patch --cover-letter --range-diff=$prev \
492 main..unmodified >actual &&
493 test_when_finished "rm 000?-*" &&
494 test_line_count = 5 actual &&
495 test_i18ngrep "^Range-diff:$" 0000-* &&
496 grep "= 1: .* s/5/A" 0000-* &&
497 grep "= 2: .* s/4/A" 0000-* &&
498 grep "= 3: .* s/11/B" 0000-* &&
499 grep "= 4: .* s/12/B" 0000-*
500 '
501 done
502
503 test_expect_success 'format-patch --range-diff as commentary' '
504 git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
505 test_when_finished "rm 0001-*" &&
506 test_line_count = 1 actual &&
507 test_i18ngrep "^Range-diff:$" 0001-* &&
508 grep "> 1: .* new message" 0001-*
509 '
510
511 test_expect_success 'range-diff overrides diff.noprefix internally' '
512 git -c diff.noprefix=true range-diff HEAD^...
513 '
514
515 test_expect_success 'basic with modified format.pretty with suffix' '
516 git -c format.pretty="format:commit %H%d%n" range-diff \
517 main..topic main..unmodified
518 '
519
520 test_expect_success 'basic with modified format.pretty without "commit "' '
521 git -c format.pretty="format:%H%n" range-diff \
522 main..topic main..unmodified
523 '
524
525 test_expect_success 'range-diff compares notes by default' '
526 git notes add -m "topic note" topic &&
527 git notes add -m "unmodified note" unmodified &&
528 test_when_finished git notes remove topic unmodified &&
529 git range-diff --no-color main..topic main..unmodified \
530 >actual &&
531 sed s/Z/\ /g >expect <<-EOF &&
532 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
533 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
534 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
535 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
536 @@ Commit message
537 Z
538 Z
539 Z ## Notes ##
540 - topic note
541 + unmodified note
542 Z
543 Z ## file ##
544 Z@@ file: A
545 EOF
546 test_cmp expect actual
547 '
548
549 test_expect_success 'range-diff with --no-notes' '
550 git notes add -m "topic note" topic &&
551 git notes add -m "unmodified note" unmodified &&
552 test_when_finished git notes remove topic unmodified &&
553 git range-diff --no-color --no-notes main..topic main..unmodified \
554 >actual &&
555 cat >expect <<-EOF &&
556 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
557 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
558 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
559 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
560 EOF
561 test_cmp expect actual
562 '
563
564 test_expect_success 'range-diff with multiple --notes' '
565 git notes --ref=note1 add -m "topic note1" topic &&
566 git notes --ref=note1 add -m "unmodified note1" unmodified &&
567 test_when_finished git notes --ref=note1 remove topic unmodified &&
568 git notes --ref=note2 add -m "topic note2" topic &&
569 git notes --ref=note2 add -m "unmodified note2" unmodified &&
570 test_when_finished git notes --ref=note2 remove topic unmodified &&
571 git range-diff --no-color --notes=note1 --notes=note2 main..topic main..unmodified \
572 >actual &&
573 sed s/Z/\ /g >expect <<-EOF &&
574 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
575 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
576 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
577 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
578 @@ Commit message
579 Z
580 Z
581 Z ## Notes (note1) ##
582 - topic note1
583 + unmodified note1
584 Z
585 Z
586 Z ## Notes (note2) ##
587 - topic note2
588 + unmodified note2
589 Z
590 Z ## file ##
591 Z@@ file: A
592 EOF
593 test_cmp expect actual
594 '
595
596 test_expect_success 'format-patch --range-diff does not compare notes by default' '
597 git notes add -m "topic note" topic &&
598 git notes add -m "unmodified note" unmodified &&
599 test_when_finished git notes remove topic unmodified &&
600 git format-patch --cover-letter --range-diff=$prev \
601 main..unmodified >actual &&
602 test_when_finished "rm 000?-*" &&
603 test_line_count = 5 actual &&
604 test_i18ngrep "^Range-diff:$" 0000-* &&
605 grep "= 1: .* s/5/A" 0000-* &&
606 grep "= 2: .* s/4/A" 0000-* &&
607 grep "= 3: .* s/11/B" 0000-* &&
608 grep "= 4: .* s/12/B" 0000-* &&
609 ! grep "Notes" 0000-* &&
610 ! grep "note" 0000-*
611 '
612
613 test_expect_success 'format-patch --range-diff with --no-notes' '
614 git notes add -m "topic note" topic &&
615 git notes add -m "unmodified note" unmodified &&
616 test_when_finished git notes remove topic unmodified &&
617 git format-patch --no-notes --cover-letter --range-diff=$prev \
618 main..unmodified >actual &&
619 test_when_finished "rm 000?-*" &&
620 test_line_count = 5 actual &&
621 test_i18ngrep "^Range-diff:$" 0000-* &&
622 grep "= 1: .* s/5/A" 0000-* &&
623 grep "= 2: .* s/4/A" 0000-* &&
624 grep "= 3: .* s/11/B" 0000-* &&
625 grep "= 4: .* s/12/B" 0000-* &&
626 ! grep "Notes" 0000-* &&
627 ! grep "note" 0000-*
628 '
629
630 test_expect_success 'format-patch --range-diff with --notes' '
631 git notes add -m "topic note" topic &&
632 git notes add -m "unmodified note" unmodified &&
633 test_when_finished git notes remove topic unmodified &&
634 git format-patch --notes --cover-letter --range-diff=$prev \
635 main..unmodified >actual &&
636 test_when_finished "rm 000?-*" &&
637 test_line_count = 5 actual &&
638 test_i18ngrep "^Range-diff:$" 0000-* &&
639 grep "= 1: .* s/5/A" 0000-* &&
640 grep "= 2: .* s/4/A" 0000-* &&
641 grep "= 3: .* s/11/B" 0000-* &&
642 grep "! 4: .* s/12/B" 0000-* &&
643 sed s/Z/\ /g >expect <<-EOF &&
644 @@ Commit message
645 Z
646 Z
647 Z ## Notes ##
648 - topic note
649 + unmodified note
650 Z
651 Z ## file ##
652 Z@@ file: A
653 EOF
654 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
655 test_cmp expect actual
656 '
657
658 test_expect_success 'format-patch --range-diff with format.notes config' '
659 git notes add -m "topic note" topic &&
660 git notes add -m "unmodified note" unmodified &&
661 test_when_finished git notes remove topic unmodified &&
662 test_config format.notes true &&
663 git format-patch --cover-letter --range-diff=$prev \
664 main..unmodified >actual &&
665 test_when_finished "rm 000?-*" &&
666 test_line_count = 5 actual &&
667 test_i18ngrep "^Range-diff:$" 0000-* &&
668 grep "= 1: .* s/5/A" 0000-* &&
669 grep "= 2: .* s/4/A" 0000-* &&
670 grep "= 3: .* s/11/B" 0000-* &&
671 grep "! 4: .* s/12/B" 0000-* &&
672 sed s/Z/\ /g >expect <<-EOF &&
673 @@ Commit message
674 Z
675 Z
676 Z ## Notes ##
677 - topic note
678 + unmodified note
679 Z
680 Z ## file ##
681 Z@@ file: A
682 EOF
683 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
684 test_cmp expect actual
685 '
686
687 test_expect_success 'format-patch --range-diff with multiple notes' '
688 git notes --ref=note1 add -m "topic note1" topic &&
689 git notes --ref=note1 add -m "unmodified note1" unmodified &&
690 test_when_finished git notes --ref=note1 remove topic unmodified &&
691 git notes --ref=note2 add -m "topic note2" topic &&
692 git notes --ref=note2 add -m "unmodified note2" unmodified &&
693 test_when_finished git notes --ref=note2 remove topic unmodified &&
694 git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
695 main..unmodified >actual &&
696 test_when_finished "rm 000?-*" &&
697 test_line_count = 5 actual &&
698 test_i18ngrep "^Range-diff:$" 0000-* &&
699 grep "= 1: .* s/5/A" 0000-* &&
700 grep "= 2: .* s/4/A" 0000-* &&
701 grep "= 3: .* s/11/B" 0000-* &&
702 grep "! 4: .* s/12/B" 0000-* &&
703 sed s/Z/\ /g >expect <<-EOF &&
704 @@ Commit message
705 Z
706 Z
707 Z ## Notes (note1) ##
708 - topic note1
709 + unmodified note1
710 Z
711 Z
712 Z ## Notes (note2) ##
713 - topic note2
714 + unmodified note2
715 Z
716 Z ## file ##
717 Z@@ file: A
718 EOF
719 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
720 test_cmp expect actual
721 '
722
723 test_done