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