3 test_description
='range-diff tests'
7 # Note that because of the range-diff's heuristics, test_commit does more
8 # harm than good. We need some real history.
10 test_expect_success
'setup' '
11 git fast-import <"$TEST_DIRECTORY"/t3206/history.export &&
12 test_oid_cache <<-\EOF
123 # Empty delimiter (included so lines match neatly)
129 test_expect_success
'simple A..B A..C (unmodified)' '
130 git range-diff --no-color master..topic master..unmodified \
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/
138 test_cmp expect actual
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
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
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/
161 test_cmp expect actual
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/
172 test_cmp expect actual
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/
184 test_cmp expect actual
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/
195 test_cmp expect actual
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/
208 test_cmp expect actual
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/
226 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
237 test_cmp expect actual
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/
248 test_cmp expect actual
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/
258 1 file changed, 1 insertion(+), 1 deletion(-)
259 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
261 1 file changed, 1 insertion(+), 1 deletion(-)
263 test_cmp expect actual
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/
281 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
292 test_cmp expect actual
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/
301 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
303 Z ## Commit message ##
305 + s/4/A/ + rename file
308 + ## file => renamed-file ##
312 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/
314 Z ## Commit message ##
324 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/
326 Z ## Commit message ##
337 test_cmp expect actual
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/
345 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
347 Z ## Commit message ##
349 + s/4/A/ + add other-file
358 + ## other-file (new) ##
359 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/
361 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
363 Z ## Commit message ##
365 + s/11/B/ + mode change other-file
374 + ## other-file (mode change 100644 => 100755) ##
375 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/
377 test_cmp expect actual
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/
386 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
388 Z ## Commit message ##
399 + ## new-file (new) ##
400 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/
402 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
404 Z ## Commit message ##
406 + s/11/B/ + remove file
415 + ## new-file (deleted) ##
416 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
418 test_cmp expect actual
421 test_expect_success
'no commits on one side' '
422 git commit --amend -m "new message" &&
423 git range-diff master HEAD@{1} HEAD
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/
432 Z ## Commit message ##
435 + Also a silly comment here!
440 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
441 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
443 test_cmp expect actual
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>
454 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
455 : <REVERSE><GREEN>+<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>
464 : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
465 : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<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>
474 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
475 : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
480 git range-diff changed...changed-message --color --dual-color >actual.raw &&
481 test_decode_color >actual <actual.raw &&
482 test_cmp expect actual
485 for prev
in topic master..topic
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-*
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-*
508 test_expect_success
'range-diff overrides diff.noprefix internally' '
509 git -c diff.noprefix=true range-diff HEAD^...
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
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
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 \
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/
543 test_cmp expect actual
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 \
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/
558 test_cmp expect actual
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 \
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/
578 Z ## Notes (note1) ##
583 Z ## Notes (note2) ##
590 test_cmp expect actual
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-* &&
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-* &&
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 &&
651 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
652 test_cmp expect actual
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 &&
680 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
681 test_cmp expect actual
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 &&
704 Z ## Notes (note1) ##
709 Z ## Notes (note2) ##
716 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
717 test_cmp expect actual