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/
256 1 file changed, 0 insertions(+), 0 deletions(-)
257 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
259 1 file changed, 0 insertions(+), 0 deletions(-)
260 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
262 1 file changed, 0 insertions(+), 0 deletions(-)
263 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
265 1 file changed, 0 insertions(+), 0 deletions(-)
267 test_cmp expect actual
270 test_expect_success 'changed commit with sm config' '
271 git range-diff --no-color --submodule=log topic...changed >actual &&
272 cat >expect <<-EOF &&
273 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
274 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
275 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
285 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
296 test_cmp expect actual
299 test_expect_success 'renamed file' '
300 git range-diff --no-color --submodule=log topic...renamed-file >actual &&
301 sed s/Z/\ /g >expect <<-EOF &&
302 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/
303 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/
305 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
307 Z ## Commit message ##
309 + s/4/A/ + rename file
312 + ## file => renamed-file ##
316 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/
318 Z ## Commit message ##
328 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/
330 Z ## Commit message ##
341 test_cmp expect actual
344 test_expect_success 'file with mode only change' '
345 git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
346 sed s/Z/\ /g >expect <<-EOF &&
347 1: $(test_oid t2) ! 1: $(test_oid o1) s/4/A/
349 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
351 Z ## Commit message ##
353 + s/4/A/ + add other-file
362 + ## other-file (new) ##
363 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/
365 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
367 Z ## Commit message ##
369 + s/11/B/ + mode change other-file
378 + ## other-file (mode change 100644 => 100755) ##
379 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/
381 test_cmp expect actual
384 test_expect_success 'file added and later removed' '
385 git range-diff --no-color --submodule=log topic...added-removed >actual &&
386 sed s/Z/\ /g >expect <<-EOF &&
387 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/
388 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/
390 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
392 Z ## Commit message ##
403 + ## new-file (new) ##
404 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/
406 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
408 Z ## Commit message ##
410 + s/11/B/ + remove file
419 + ## new-file (deleted) ##
420 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
422 test_cmp expect actual
425 test_expect_success 'no commits on one side' '
426 git commit --amend -m "new message" &&
427 git range-diff master HEAD@{1} HEAD
430 test_expect_success 'changed message' '
431 git range-diff --no-color topic...changed-message >actual &&
432 sed s/Z/\ /g >expect <<-EOF &&
433 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/
434 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/
436 Z ## Commit message ##
439 + Also a silly comment here!
444 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
445 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
447 test_cmp expect actual
450 test_expect_success 'dual-coloring' '
451 sed -e "s|^:||" >expect <<-EOF &&
452 :<YELLOW>1: $(test_oid c1) = 1: $(test_oid m1) s/5/A/<RESET>
453 :<RED>2: $(test_oid c2) <RESET><YELLOW>!<RESET><GREEN> 2: $(test_oid m2)<RESET><YELLOW> s/4/A/<RESET>
454 : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
455 : ## Commit message ##<RESET>
458 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
459 : <REVERSE><GREEN>+<RESET>
463 :<RED>3: $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3: $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET>
464 : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
468 : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
469 : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET>
473 :<RED>4: $(test_oid c4) <RESET><YELLOW>!<RESET><GREEN> 4: $(test_oid m4)<RESET><YELLOW> s/12/B/<RESET>
474 : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
475 : <CYAN> @@ file: A<RESET>
478 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
479 : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
484 git range-diff changed...changed-message --color --dual-color >actual.raw &&
485 test_decode_color >actual <actual.raw &&
486 test_cmp expect actual
489 for prev in topic master..topic
491 test_expect_success "format-patch --range-diff=$prev" '
492 git format-patch --cover-letter --range-diff=$prev \
493 master..unmodified >actual &&
494 test_when_finished "rm 000?-*" &&
495 test_line_count = 5 actual &&
496 test_i18ngrep "^Range-diff:$" 0000-* &&
497 grep "= 1: .* s/5/A" 0000-* &&
498 grep "= 2: .* s/4/A" 0000-* &&
499 grep "= 3: .* s/11/B" 0000-* &&
500 grep "= 4: .* s/12/B" 0000-*
504 test_expect_success 'format-patch --range-diff as commentary' '
505 git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
506 test_when_finished "rm 0001-*" &&
507 test_line_count = 1 actual &&
508 test_i18ngrep "^Range-diff:$" 0001-* &&
509 grep "> 1: .* new message" 0001-*
512 test_expect_success 'range-diff overrides diff.noprefix internally' '
513 git -c diff.noprefix=true range-diff HEAD^...
516 test_expect_success 'basic with modified format.pretty with suffix' '
517 git -c format.pretty="format:commit %H%d%n" range-diff \
518 master..topic master..unmodified
521 test_expect_success 'basic with modified format.pretty without "commit "' '
522 git -c format.pretty="format:%H%n" range-diff \
523 master..topic master..unmodified
526 test_expect_success 'range-diff compares notes by default' '
527 git notes add -m "topic note" topic &&
528 git notes add -m "unmodified note" unmodified &&
529 test_when_finished git notes remove topic unmodified &&
530 git range-diff --no-color master..topic master..unmodified \
532 sed s/Z/\ /g >expect <<-EOF &&
533 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
534 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
535 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
536 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
547 test_cmp expect actual
550 test_expect_success 'range-diff with --no-notes' '
551 git notes add -m "topic note" topic &&
552 git notes add -m "unmodified note" unmodified &&
553 test_when_finished git notes remove topic unmodified &&
554 git range-diff --no-color --no-notes master..topic master..unmodified \
556 cat >expect <<-EOF &&
557 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
558 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
559 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
560 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
562 test_cmp expect actual
565 test_expect_success 'range-diff with multiple --notes' '
566 git notes --ref=note1 add -m "topic note1" topic &&
567 git notes --ref=note1 add -m "unmodified note1" unmodified &&
568 test_when_finished git notes --ref=note1 remove topic unmodified &&
569 git notes --ref=note2 add -m "topic note2" topic &&
570 git notes --ref=note2 add -m "unmodified note2" unmodified &&
571 test_when_finished git notes --ref=note2 remove topic unmodified &&
572 git range-diff --no-color --notes=note1 --notes=note2 master..topic master..unmodified \
574 sed s/Z/\ /g >expect <<-EOF &&
575 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
576 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
577 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
578 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
582 Z ## Notes (note1) ##
587 Z ## Notes (note2) ##
594 test_cmp expect actual
597 test_expect_success 'format-patch --range-diff does not compare notes by default' '
598 git notes add -m "topic note" topic &&
599 git notes add -m "unmodified note" unmodified &&
600 test_when_finished git notes remove topic unmodified &&
601 git format-patch --cover-letter --range-diff=$prev \
602 master..unmodified >actual &&
603 test_when_finished "rm 000?-*" &&
604 test_line_count = 5 actual &&
605 test_i18ngrep "^Range-diff:$" 0000-* &&
606 grep "= 1: .* s/5/A" 0000-* &&
607 grep "= 2: .* s/4/A" 0000-* &&
608 grep "= 3: .* s/11/B" 0000-* &&
609 grep "= 4: .* s/12/B" 0000-* &&
610 ! grep "Notes" 0000-* &&
614 test_expect_success 'format-patch --range-diff with --no-notes' '
615 git notes add -m "topic note" topic &&
616 git notes add -m "unmodified note" unmodified &&
617 test_when_finished git notes remove topic unmodified &&
618 git format-patch --no-notes --cover-letter --range-diff=$prev \
619 master..unmodified >actual &&
620 test_when_finished "rm 000?-*" &&
621 test_line_count = 5 actual &&
622 test_i18ngrep "^Range-diff:$" 0000-* &&
623 grep "= 1: .* s/5/A" 0000-* &&
624 grep "= 2: .* s/4/A" 0000-* &&
625 grep "= 3: .* s/11/B" 0000-* &&
626 grep "= 4: .* s/12/B" 0000-* &&
627 ! grep "Notes" 0000-* &&
631 test_expect_success 'format-patch --range-diff with --notes' '
632 git notes add -m "topic note" topic &&
633 git notes add -m "unmodified note" unmodified &&
634 test_when_finished git notes remove topic unmodified &&
635 git format-patch --notes --cover-letter --range-diff=$prev \
636 master..unmodified >actual &&
637 test_when_finished "rm 000?-*" &&
638 test_line_count = 5 actual &&
639 test_i18ngrep "^Range-diff:$" 0000-* &&
640 grep "= 1: .* s/5/A" 0000-* &&
641 grep "= 2: .* s/4/A" 0000-* &&
642 grep "= 3: .* s/11/B" 0000-* &&
643 grep "! 4: .* s/12/B" 0000-* &&
644 sed s/Z/\ /g >expect <<-EOF &&
655 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
656 test_cmp expect actual
659 test_expect_success 'format-patch --range-diff with format.notes config' '
660 git notes add -m "topic note" topic &&
661 git notes add -m "unmodified note" unmodified &&
662 test_when_finished git notes remove topic unmodified &&
663 test_config format.notes true &&
664 git format-patch --cover-letter --range-diff=$prev \
665 master..unmodified >actual &&
666 test_when_finished "rm 000?-*" &&
667 test_line_count = 5 actual &&
668 test_i18ngrep "^Range-diff:$" 0000-* &&
669 grep "= 1: .* s/5/A" 0000-* &&
670 grep "= 2: .* s/4/A" 0000-* &&
671 grep "= 3: .* s/11/B" 0000-* &&
672 grep "! 4: .* s/12/B" 0000-* &&
673 sed s/Z/\ /g >expect <<-EOF &&
684 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
685 test_cmp expect actual
688 test_expect_success 'format-patch --range-diff with multiple notes' '
689 git notes --ref=note1 add -m "topic note1" topic &&
690 git notes --ref=note1 add -m "unmodified note1" unmodified &&
691 test_when_finished git notes --ref=note1 remove topic unmodified &&
692 git notes --ref=note2 add -m "topic note2" topic &&
693 git notes --ref=note2 add -m "unmodified note2" unmodified &&
694 test_when_finished git notes --ref=note2 remove topic unmodified &&
695 git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
696 master..unmodified >actual &&
697 test_when_finished "rm 000?-*" &&
698 test_line_count = 5 actual &&
699 test_i18ngrep "^Range-diff:$" 0000-* &&
700 grep "= 1: .* s/5/A" 0000-* &&
701 grep "= 2: .* s/4/A" 0000-* &&
702 grep "= 3: .* s/11/B" 0000-* &&
703 grep "! 4: .* s/12/B" 0000-* &&
704 sed s/Z/\ /g >expect <<-EOF &&
708 Z ## Notes (note1) ##
713 Z ## Notes (note2) ##
720 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
721 test_cmp expect actual