summaryrefslogtreecommitdiff
path: root/t/t3206-range-diff.sh
blob: bd808f87ed5bdf0de3f07299cc25d877219aa7ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
#!/bin/sh

test_description='range-diff tests'

. ./test-lib.sh

# Note that because of the range-diff's heuristics, test_commit does more
# harm than good.  We need some real history.

test_expect_success 'setup' '
	git fast-import <"$TEST_DIRECTORY"/t3206/history.export &&
	test_oid_cache <<-\EOF
	# topic
	t1 sha1:4de457d
	t2 sha1:fccce22
	t3 sha1:147e64e
	t4 sha1:a63e992
	t1 sha256:b89f8b9
	t2 sha256:5f12aad
	t3 sha256:ea8b273
	t4 sha256:14b7336

	# unmodified
	u1 sha1:35b9b25
	u2 sha1:de345ab
	u3 sha1:9af6654
	u4 sha1:2901f77
	u1 sha256:e3731be
	u2 sha256:14fadf8
	u3 sha256:736c4bc
	u4 sha256:673e77d

	# reordered
	r1 sha1:aca177a
	r2 sha1:14ad629
	r3 sha1:ee58208
	r4 sha1:307b27a
	r1 sha256:f59d3aa
	r2 sha256:fb261a8
	r3 sha256:cb2649b
	r4 sha256:958577e

	# removed (deleted)
	d1 sha1:7657159
	d2 sha1:43d84d3
	d3 sha1:a740396
	d1 sha256:e312513
	d2 sha256:eb19258
	d3 sha256:1ccb3c1

	# added
	a1 sha1:2716022
	a2 sha1:b62accd
	a3 sha1:df46cfa
	a4 sha1:3e64548
	a5 sha1:12b4063
	a1 sha256:d724f4d
	a2 sha256:1de7762
	a3 sha256:e159431
	a4 sha256:b3e483c
	a5 sha256:90866a7

	# rebased
	b1 sha1:cc9c443
	b2 sha1:c5d9641
	b3 sha1:28cc2b6
	b4 sha1:5628ab7
	b5 sha1:a31b12e
	b1 sha256:a1a8717
	b2 sha256:20a5862
	b3 sha256:587172a
	b4 sha256:2721c5d
	b5 sha256:7b57864

	# changed
	c1 sha1:a4b3333
	c2 sha1:f51d370
	c3 sha1:0559556
	c4 sha1:d966c5c
	c1 sha256:f8c2b9d
	c2 sha256:3fb6318
	c3 sha256:168ab68
	c4 sha256:3526539

	# changed-message
	m1 sha1:f686024
	m2 sha1:4ab067d
	m3 sha1:b9cb956
	m4 sha1:8add5f1
	m1 sha256:31e6281
	m2 sha256:a06bf1b
	m3 sha256:82dc654
	m4 sha256:48470c5

	# renamed
	n1 sha1:f258d75
	n2 sha1:017b62d
	n3 sha1:3ce7af6
	n4 sha1:1e6226b
	n1 sha256:ad52114
	n2 sha256:3b54c8f
	n3 sha256:3b0a644
	n4 sha256:e461653

	# mode change
	o1 sha1:4d39cb3
	o2 sha1:26c107f
	o3 sha1:4c1e0f5
	o1 sha256:d0dd598
	o2 sha256:c4a279e
	o3 sha256:78459d7

	# added and removed
	s1 sha1:096b1ba
	s2 sha1:d92e698
	s3 sha1:9a1db4d
	s4 sha1:fea3b5c
	s1 sha256:a7f9134
	s2 sha256:b4c2580
	s3 sha256:1d62aa2
	s4 sha256:48160e8

	# Empty delimiter (included so lines match neatly)
	__ sha1:-------
	__ sha256:-------
	EOF
'

test_expect_success 'simple A..B A..C (unmodified)' '
	git range-diff --no-color master..topic master..unmodified \
		>actual &&
	cat >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid u1) s/5/A/
	2:  $(test_oid t2) = 2:  $(test_oid u2) s/4/A/
	3:  $(test_oid t3) = 3:  $(test_oid u3) s/11/B/
	4:  $(test_oid t4) = 4:  $(test_oid u4) s/12/B/
	EOF
	test_cmp expect actual
'

test_expect_success 'simple B...C (unmodified)' '
	git range-diff --no-color topic...unmodified >actual &&
	# same "expect" as above
	test_cmp expect actual
'

test_expect_success 'simple A B C (unmodified)' '
	git range-diff --no-color master topic unmodified >actual &&
	# same "expect" as above
	test_cmp expect actual
'

test_expect_success 'trivial reordering' '
	git range-diff --no-color master topic reordered >actual &&
	cat >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid r1) s/5/A/
	3:  $(test_oid t3) = 2:  $(test_oid r2) s/11/B/
	4:  $(test_oid t4) = 3:  $(test_oid r3) s/12/B/
	2:  $(test_oid t2) = 4:  $(test_oid r4) s/4/A/
	EOF
	test_cmp expect actual
'

test_expect_success 'removed a commit' '
	git range-diff --no-color master topic removed >actual &&
	cat >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid d1) s/5/A/
	2:  $(test_oid t2) < -:  $(test_oid __) s/4/A/
	3:  $(test_oid t3) = 2:  $(test_oid d2) s/11/B/
	4:  $(test_oid t4) = 3:  $(test_oid d3) s/12/B/
	EOF
	test_cmp expect actual
'

test_expect_success 'added a commit' '
	git range-diff --no-color master topic added >actual &&
	cat >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid a1) s/5/A/
	2:  $(test_oid t2) = 2:  $(test_oid a2) s/4/A/
	-:  $(test_oid __) > 3:  $(test_oid a3) s/6/A/
	3:  $(test_oid t3) = 4:  $(test_oid a4) s/11/B/
	4:  $(test_oid t4) = 5:  $(test_oid a5) s/12/B/
	EOF
	test_cmp expect actual
'

test_expect_success 'new base, A B C' '
	git range-diff --no-color master topic rebased >actual &&
	cat >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid b1) s/5/A/
	2:  $(test_oid t2) = 2:  $(test_oid b2) s/4/A/
	3:  $(test_oid t3) = 3:  $(test_oid b3) s/11/B/
	4:  $(test_oid t4) = 4:  $(test_oid b4) s/12/B/
	EOF
	test_cmp expect actual
'

test_expect_success 'new base, B...C' '
	# this syntax includes the commits from master!
	git range-diff --no-color topic...rebased >actual &&
	cat >expect <<-EOF &&
	-:  $(test_oid __) > 1:  $(test_oid b5) unrelated
	1:  $(test_oid t1) = 2:  $(test_oid b1) s/5/A/
	2:  $(test_oid t2) = 3:  $(test_oid b2) s/4/A/
	3:  $(test_oid t3) = 4:  $(test_oid b3) s/11/B/
	4:  $(test_oid t4) = 5:  $(test_oid b4) s/12/B/
	EOF
	test_cmp expect actual
'

test_expect_success 'changed commit' '
	git range-diff --no-color topic...changed >actual &&
	cat >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid c1) s/5/A/
	2:  $(test_oid t2) = 2:  $(test_oid c2) s/4/A/
	3:  $(test_oid t3) ! 3:  $(test_oid c3) s/11/B/
	    @@ file: A
	      9
	      10
	     -11
	    -+B
	    ++BB
	      12
	      13
	      14
	4:  $(test_oid t4) ! 4:  $(test_oid c4) s/12/B/
	    @@ file
	     @@ file: A
	      9
	      10
	    - B
	    + BB
	     -12
	     +B
	      13
	EOF
	test_cmp expect actual
'

test_expect_success 'changed commit with --no-patch diff option' '
	git range-diff --no-color --no-patch topic...changed >actual &&
	cat >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid c1) s/5/A/
	2:  $(test_oid t2) = 2:  $(test_oid c2) s/4/A/
	3:  $(test_oid t3) ! 3:  $(test_oid c3) s/11/B/
	4:  $(test_oid t4) ! 4:  $(test_oid c4) s/12/B/
	EOF
	test_cmp expect actual
'

test_expect_success 'changed commit with --stat diff option' '
	git range-diff --no-color --stat topic...changed >actual &&
	cat >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid c1) s/5/A/
	     a => b | 0
	     1 file changed, 0 insertions(+), 0 deletions(-)
	2:  $(test_oid t2) = 2:  $(test_oid c2) s/4/A/
	     a => b | 0
	     1 file changed, 0 insertions(+), 0 deletions(-)
	3:  $(test_oid t3) ! 3:  $(test_oid c3) s/11/B/
	     a => b | 0
	     1 file changed, 0 insertions(+), 0 deletions(-)
	4:  $(test_oid t4) ! 4:  $(test_oid c4) s/12/B/
	     a => b | 0
	     1 file changed, 0 insertions(+), 0 deletions(-)
	EOF
	test_cmp expect actual
'

test_expect_success 'changed commit with sm config' '
	git range-diff --no-color --submodule=log topic...changed >actual &&
	cat >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid c1) s/5/A/
	2:  $(test_oid t2) = 2:  $(test_oid c2) s/4/A/
	3:  $(test_oid t3) ! 3:  $(test_oid c3) s/11/B/
	    @@ file: A
	      9
	      10
	     -11
	    -+B
	    ++BB
	      12
	      13
	      14
	4:  $(test_oid t4) ! 4:  $(test_oid c4) s/12/B/
	    @@ file
	     @@ file: A
	      9
	      10
	    - B
	    + BB
	     -12
	     +B
	      13
	EOF
	test_cmp expect actual
'

test_expect_success 'renamed file' '
	git range-diff --no-color --submodule=log topic...renamed-file >actual &&
	sed s/Z/\ /g >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid n1) s/5/A/
	2:  $(test_oid t2) ! 2:  $(test_oid n2) s/4/A/
	    @@ Metadata
	    ZAuthor: Thomas Rast <trast@inf.ethz.ch>
	    Z
	    Z ## Commit message ##
	    -    s/4/A/
	    +    s/4/A/ + rename file
	    Z
	    - ## file ##
	    + ## file => renamed-file ##
	    Z@@
	    Z 1
	    Z 2
	3:  $(test_oid t3) ! 3:  $(test_oid n3) s/11/B/
	    @@ Metadata
	    Z ## Commit message ##
	    Z    s/11/B/
	    Z
	    - ## file ##
	    -@@ file: A
	    + ## renamed-file ##
	    +@@ renamed-file: A
	    Z 8
	    Z 9
	    Z 10
	4:  $(test_oid t4) ! 4:  $(test_oid n4) s/12/B/
	    @@ Metadata
	    Z ## Commit message ##
	    Z    s/12/B/
	    Z
	    - ## file ##
	    -@@ file: A
	    + ## renamed-file ##
	    +@@ renamed-file: A
	    Z 9
	    Z 10
	    Z B
	EOF
	test_cmp expect actual
'

test_expect_success 'file with mode only change' '
	git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
	sed s/Z/\ /g >expect <<-EOF &&
	1:  $(test_oid t2) ! 1:  $(test_oid o1) s/4/A/
	    @@ Metadata
	    ZAuthor: Thomas Rast <trast@inf.ethz.ch>
	    Z
	    Z ## Commit message ##
	    -    s/4/A/
	    +    s/4/A/ + add other-file
	    Z
	    Z ## file ##
	    Z@@
	    @@ file
	    Z A
	    Z 6
	    Z 7
	    +
	    + ## other-file (new) ##
	2:  $(test_oid t3) ! 2:  $(test_oid o2) s/11/B/
	    @@ Metadata
	    ZAuthor: Thomas Rast <trast@inf.ethz.ch>
	    Z
	    Z ## Commit message ##
	    -    s/11/B/
	    +    s/11/B/ + mode change other-file
	    Z
	    Z ## file ##
	    Z@@ file: A
	    @@ file: A
	    Z 12
	    Z 13
	    Z 14
	    +
	    + ## other-file (mode change 100644 => 100755) ##
	3:  $(test_oid t4) = 3:  $(test_oid o3) s/12/B/
	EOF
	test_cmp expect actual
'

test_expect_success 'file added and later removed' '
	git range-diff --no-color --submodule=log topic...added-removed >actual &&
	sed s/Z/\ /g >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid s1) s/5/A/
	2:  $(test_oid t2) ! 2:  $(test_oid s2) s/4/A/
	    @@ Metadata
	    ZAuthor: Thomas Rast <trast@inf.ethz.ch>
	    Z
	    Z ## Commit message ##
	    -    s/4/A/
	    +    s/4/A/ + new-file
	    Z
	    Z ## file ##
	    Z@@
	    @@ file
	    Z A
	    Z 6
	    Z 7
	    +
	    + ## new-file (new) ##
	3:  $(test_oid t3) ! 3:  $(test_oid s3) s/11/B/
	    @@ Metadata
	    ZAuthor: Thomas Rast <trast@inf.ethz.ch>
	    Z
	    Z ## Commit message ##
	    -    s/11/B/
	    +    s/11/B/ + remove file
	    Z
	    Z ## file ##
	    Z@@ file: A
	    @@ file: A
	    Z 12
	    Z 13
	    Z 14
	    +
	    + ## new-file (deleted) ##
	4:  $(test_oid t4) = 4:  $(test_oid s4) s/12/B/
	EOF
	test_cmp expect actual
'

test_expect_success 'no commits on one side' '
	git commit --amend -m "new message" &&
	git range-diff master HEAD@{1} HEAD
'

test_expect_success 'changed message' '
	git range-diff --no-color topic...changed-message >actual &&
	sed s/Z/\ /g >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid m1) s/5/A/
	2:  $(test_oid t2) ! 2:  $(test_oid m2) s/4/A/
	    @@ Metadata
	    Z ## Commit message ##
	    Z    s/4/A/
	    Z
	    +    Also a silly comment here!
	    +
	    Z ## file ##
	    Z@@
	    Z 1
	3:  $(test_oid t3) = 3:  $(test_oid m3) s/11/B/
	4:  $(test_oid t4) = 4:  $(test_oid m4) s/12/B/
	EOF
	test_cmp expect actual
'

test_expect_success 'dual-coloring' '
	sed -e "s|^:||" >expect <<-EOF &&
	:<YELLOW>1:  $(test_oid c1) = 1:  $(test_oid m1) s/5/A/<RESET>
	:<RED>2:  $(test_oid c2) <RESET><YELLOW>!<RESET><GREEN> 2:  $(test_oid m2)<RESET><YELLOW> s/4/A/<RESET>
	:    <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
	:      ## Commit message ##<RESET>
	:         s/4/A/<RESET>
	:     <RESET>
	:    <REVERSE><GREEN>+<RESET><BOLD>    Also a silly comment here!<RESET>
	:    <REVERSE><GREEN>+<RESET>
	:      ## file ##<RESET>
	:    <CYAN> @@<RESET>
	:      1<RESET>
	:<RED>3:  $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3:  $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET>
	:    <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
	:      9<RESET>
	:      10<RESET>
	:    <RED> -11<RESET>
	:    <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
	:    <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET>
	:      12<RESET>
	:      13<RESET>
	:      14<RESET>
	:<RED>4:  $(test_oid c4) <RESET><YELLOW>!<RESET><GREEN> 4:  $(test_oid m4)<RESET><YELLOW> s/12/B/<RESET>
	:    <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
	:    <CYAN> @@ file: A<RESET>
	:      9<RESET>
	:      10<RESET>
	:    <REVERSE><RED>-<RESET><FAINT> BB<RESET>
	:    <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
	:    <RED> -12<RESET>
	:    <GREEN> +B<RESET>
	:      13<RESET>
	EOF
	git range-diff changed...changed-message --color --dual-color >actual.raw &&
	test_decode_color >actual <actual.raw &&
	test_cmp expect actual
'

for prev in topic master..topic
do
	test_expect_success "format-patch --range-diff=$prev" '
		git format-patch --cover-letter --range-diff=$prev \
			master..unmodified >actual &&
		test_when_finished "rm 000?-*" &&
		test_line_count = 5 actual &&
		test_i18ngrep "^Range-diff:$" 0000-* &&
		grep "= 1: .* s/5/A" 0000-* &&
		grep "= 2: .* s/4/A" 0000-* &&
		grep "= 3: .* s/11/B" 0000-* &&
		grep "= 4: .* s/12/B" 0000-*
	'
done

test_expect_success 'format-patch --range-diff as commentary' '
	git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
	test_when_finished "rm 0001-*" &&
	test_line_count = 1 actual &&
	test_i18ngrep "^Range-diff:$" 0001-* &&
	grep "> 1: .* new message" 0001-*
'

test_expect_success 'range-diff overrides diff.noprefix internally' '
	git -c diff.noprefix=true range-diff HEAD^...
'

test_expect_success 'range-diff compares notes by default' '
	git notes add -m "topic note" topic &&
	git notes add -m "unmodified note" unmodified &&
	test_when_finished git notes remove topic unmodified &&
	git range-diff --no-color master..topic master..unmodified \
		>actual &&
	sed s/Z/\ /g >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid u1) s/5/A/
	2:  $(test_oid t2) = 2:  $(test_oid u2) s/4/A/
	3:  $(test_oid t3) = 3:  $(test_oid u3) s/11/B/
	4:  $(test_oid t4) ! 4:  $(test_oid u4) s/12/B/
	    @@ Commit message
	    Z
	    Z
	    Z ## Notes ##
	    -    topic note
	    +    unmodified note
	    Z
	    Z ## file ##
	    Z@@ file: A
	EOF
	test_cmp expect actual
'

test_expect_success 'range-diff with --no-notes' '
	git notes add -m "topic note" topic &&
	git notes add -m "unmodified note" unmodified &&
	test_when_finished git notes remove topic unmodified &&
	git range-diff --no-color --no-notes master..topic master..unmodified \
		>actual &&
	cat >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid u1) s/5/A/
	2:  $(test_oid t2) = 2:  $(test_oid u2) s/4/A/
	3:  $(test_oid t3) = 3:  $(test_oid u3) s/11/B/
	4:  $(test_oid t4) = 4:  $(test_oid u4) s/12/B/
	EOF
	test_cmp expect actual
'

test_expect_success 'range-diff with multiple --notes' '
	git notes --ref=note1 add -m "topic note1" topic &&
	git notes --ref=note1 add -m "unmodified note1" unmodified &&
	test_when_finished git notes --ref=note1 remove topic unmodified &&
	git notes --ref=note2 add -m "topic note2" topic &&
	git notes --ref=note2 add -m "unmodified note2" unmodified &&
	test_when_finished git notes --ref=note2 remove topic unmodified &&
	git range-diff --no-color --notes=note1 --notes=note2 master..topic master..unmodified \
		>actual &&
	sed s/Z/\ /g >expect <<-EOF &&
	1:  $(test_oid t1) = 1:  $(test_oid u1) s/5/A/
	2:  $(test_oid t2) = 2:  $(test_oid u2) s/4/A/
	3:  $(test_oid t3) = 3:  $(test_oid u3) s/11/B/
	4:  $(test_oid t4) ! 4:  $(test_oid u4) s/12/B/
	    @@ Commit message
	    Z
	    Z
	    Z ## Notes (note1) ##
	    -    topic note1
	    +    unmodified note1
	    Z
	    Z
	    Z ## Notes (note2) ##
	    -    topic note2
	    +    unmodified note2
	    Z
	    Z ## file ##
	    Z@@ file: A
	EOF
	test_cmp expect actual
'

test_expect_success 'format-patch --range-diff does not compare notes by default' '
	git notes add -m "topic note" topic &&
	git notes add -m "unmodified note" unmodified &&
	test_when_finished git notes remove topic unmodified &&
	git format-patch --cover-letter --range-diff=$prev \
		master..unmodified >actual &&
	test_when_finished "rm 000?-*" &&
	test_line_count = 5 actual &&
	test_i18ngrep "^Range-diff:$" 0000-* &&
	grep "= 1: .* s/5/A" 0000-* &&
	grep "= 2: .* s/4/A" 0000-* &&
	grep "= 3: .* s/11/B" 0000-* &&
	grep "= 4: .* s/12/B" 0000-* &&
	! grep "Notes" 0000-* &&
	! grep "note" 0000-*
'

test_expect_success 'format-patch --range-diff with --no-notes' '
	git notes add -m "topic note" topic &&
	git notes add -m "unmodified note" unmodified &&
	test_when_finished git notes remove topic unmodified &&
	git format-patch --no-notes --cover-letter --range-diff=$prev \
		master..unmodified >actual &&
	test_when_finished "rm 000?-*" &&
	test_line_count = 5 actual &&
	test_i18ngrep "^Range-diff:$" 0000-* &&
	grep "= 1: .* s/5/A" 0000-* &&
	grep "= 2: .* s/4/A" 0000-* &&
	grep "= 3: .* s/11/B" 0000-* &&
	grep "= 4: .* s/12/B" 0000-* &&
	! grep "Notes" 0000-* &&
	! grep "note" 0000-*
'

test_expect_success 'format-patch --range-diff with --notes' '
	git notes add -m "topic note" topic &&
	git notes add -m "unmodified note" unmodified &&
	test_when_finished git notes remove topic unmodified &&
	git format-patch --notes --cover-letter --range-diff=$prev \
		master..unmodified >actual &&
	test_when_finished "rm 000?-*" &&
	test_line_count = 5 actual &&
	test_i18ngrep "^Range-diff:$" 0000-* &&
	grep "= 1: .* s/5/A" 0000-* &&
	grep "= 2: .* s/4/A" 0000-* &&
	grep "= 3: .* s/11/B" 0000-* &&
	grep "! 4: .* s/12/B" 0000-* &&
	sed s/Z/\ /g >expect <<-EOF &&
	    @@ Commit message
	    Z
	    Z
	    Z ## Notes ##
	    -    topic note
	    +    unmodified note
	    Z
	    Z ## file ##
	    Z@@ file: A
	EOF
	sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
	test_cmp expect actual
'

test_expect_success 'format-patch --range-diff with format.notes config' '
	git notes add -m "topic note" topic &&
	git notes add -m "unmodified note" unmodified &&
	test_when_finished git notes remove topic unmodified &&
	test_config format.notes true &&
	git format-patch --cover-letter --range-diff=$prev \
		master..unmodified >actual &&
	test_when_finished "rm 000?-*" &&
	test_line_count = 5 actual &&
	test_i18ngrep "^Range-diff:$" 0000-* &&
	grep "= 1: .* s/5/A" 0000-* &&
	grep "= 2: .* s/4/A" 0000-* &&
	grep "= 3: .* s/11/B" 0000-* &&
	grep "! 4: .* s/12/B" 0000-* &&
	sed s/Z/\ /g >expect <<-EOF &&
	    @@ Commit message
	    Z
	    Z
	    Z ## Notes ##
	    -    topic note
	    +    unmodified note
	    Z
	    Z ## file ##
	    Z@@ file: A
	EOF
	sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
	test_cmp expect actual
'

test_expect_success 'format-patch --range-diff with multiple notes' '
	git notes --ref=note1 add -m "topic note1" topic &&
	git notes --ref=note1 add -m "unmodified note1" unmodified &&
	test_when_finished git notes --ref=note1 remove topic unmodified &&
	git notes --ref=note2 add -m "topic note2" topic &&
	git notes --ref=note2 add -m "unmodified note2" unmodified &&
	test_when_finished git notes --ref=note2 remove topic unmodified &&
	git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
		master..unmodified >actual &&
	test_when_finished "rm 000?-*" &&
	test_line_count = 5 actual &&
	test_i18ngrep "^Range-diff:$" 0000-* &&
	grep "= 1: .* s/5/A" 0000-* &&
	grep "= 2: .* s/4/A" 0000-* &&
	grep "= 3: .* s/11/B" 0000-* &&
	grep "! 4: .* s/12/B" 0000-* &&
	sed s/Z/\ /g >expect <<-EOF &&
	    @@ Commit message
	    Z
	    Z
	    Z ## Notes (note1) ##
	    -    topic note1
	    +    unmodified note1
	    Z
	    Z
	    Z ## Notes (note2) ##
	    -    topic note2
	    +    unmodified note2
	    Z
	    Z ## file ##
	    Z@@ file: A
	EOF
	sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
	test_cmp expect actual
'

test_done