3 test_description='range-diff tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 # Note that because of the range-diff's heuristics, test_commit does more
11 # harm than good. We need some real history.
13 test_expect_success 'setup' '
14 git fast-import <"$TEST_DIRECTORY"/t3206/history.export &&
15 test_oid_cache <<-\EOF
126 # Empty delimiter (included so lines match neatly)
132 test_expect_success 'simple A..B A..C (unmodified)' '
133 git range-diff --no-color main..topic main..unmodified \
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/
141 test_cmp expect actual
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
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
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/
164 test_cmp expect actual
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/
175 test_cmp expect actual
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/
187 test_cmp expect actual
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/
198 test_cmp expect actual
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/
211 test_cmp expect actual
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/
229 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
240 test_cmp expect actual
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/
251 test_cmp expect actual
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/
261 1 file changed, 1 insertion(+), 1 deletion(-)
262 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
264 1 file changed, 1 insertion(+), 1 deletion(-)
266 test_cmp expect actual
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/
284 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
295 test_cmp expect actual
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/
304 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
306 Z ## Commit message ##
308 + s/4/A/ + rename file
311 + ## file => renamed-file ##
315 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/
317 Z ## Commit message ##
327 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/
329 Z ## Commit message ##
340 test_cmp expect actual
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/
348 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
350 Z ## Commit message ##
352 + s/4/A/ + add other-file
361 + ## other-file (new) ##
362 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/
364 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
366 Z ## Commit message ##
368 + s/11/B/ + mode change other-file
377 + ## other-file (mode change 100644 => 100755) ##
378 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/
380 test_cmp expect actual
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/
389 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
391 Z ## Commit message ##
402 + ## new-file (new) ##
403 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/
405 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
407 Z ## Commit message ##
409 + s/11/B/ + remove file
418 + ## new-file (deleted) ##
419 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
421 test_cmp expect actual
424 test_expect_success 'no commits on one side' '
425 git commit --amend -m "new message" &&
426 git range-diff main HEAD@{1} HEAD
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/
435 Z ## Commit message ##
438 + Also a silly comment here!
443 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
444 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
446 test_cmp expect actual
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>
457 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
458 : <REVERSE><GREEN>+<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>
467 : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
468 : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<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>
477 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
478 : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
483 git range-diff changed...changed-message --color --dual-color >actual.raw &&
484 test_decode_color >actual <actual.raw &&
485 test_cmp expect actual
488 for prev in topic main..topic
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-*
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-*
511 test_expect_success 'range-diff overrides diff.noprefix internally' '
512 git -c diff.noprefix=true range-diff HEAD^...
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
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
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 \
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/
546 test_cmp expect actual
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 \
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/
561 test_cmp expect actual
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 \
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/
581 Z ## Notes (note1) ##
586 Z ## Notes (note2) ##
593 test_cmp expect actual
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-* &&
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-* &&
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 &&
654 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
655 test_cmp expect actual
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 &&
683 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
684 test_cmp expect actual
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 &&
707 Z ## Notes (note1) ##
712 Z ## Notes (note2) ##
719 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
720 test_cmp expect actual