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
115 # Empty delimiter (included so lines match neatly)
121 test_expect_success 'simple A..B A..C (unmodified)' '
122 git range-diff --no-color master..topic master..unmodified \
124 cat >expect <<-EOF &&
125 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
126 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
127 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
128 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
130 test_cmp expect actual
133 test_expect_success 'simple B...C (unmodified)' '
134 git range-diff --no-color topic...unmodified >actual &&
135 # same "expect" as above
136 test_cmp expect actual
139 test_expect_success 'simple A B C (unmodified)' '
140 git range-diff --no-color master topic unmodified >actual &&
141 # same "expect" as above
142 test_cmp expect actual
145 test_expect_success 'trivial reordering' '
146 git range-diff --no-color master topic reordered >actual &&
147 cat >expect <<-EOF &&
148 1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/
149 3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/
150 4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/
151 2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/
153 test_cmp expect actual
156 test_expect_success 'removed a commit' '
157 git range-diff --no-color master topic removed >actual &&
158 cat >expect <<-EOF &&
159 1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/
160 2: $(test_oid t2) < -: $(test_oid __) s/4/A/
161 3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/
162 4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/
164 test_cmp expect actual
167 test_expect_success 'added a commit' '
168 git range-diff --no-color master topic added >actual &&
169 cat >expect <<-EOF &&
170 1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/
171 2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/
172 -: $(test_oid __) > 3: $(test_oid a3) s/6/A/
173 3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/
174 4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/
176 test_cmp expect actual
179 test_expect_success 'new base, A B C' '
180 git range-diff --no-color master topic rebased >actual &&
181 cat >expect <<-EOF &&
182 1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/
183 2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/
184 3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/
185 4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/
187 test_cmp expect actual
190 test_expect_success 'new base, B...C' '
191 # this syntax includes the commits from master!
192 git range-diff --no-color topic...rebased >actual &&
193 cat >expect <<-EOF &&
194 -: $(test_oid __) > 1: $(test_oid b5) unrelated
195 1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/
196 2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/
197 3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/
198 4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/
200 test_cmp expect actual
203 test_expect_success 'changed commit' '
204 git range-diff --no-color topic...changed >actual &&
205 cat >expect <<-EOF &&
206 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
207 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
208 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
218 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
229 test_cmp expect actual
232 test_expect_success 'changed commit with --no-patch diff option' '
233 git range-diff --no-color --no-patch topic...changed >actual &&
234 cat >expect <<-EOF &&
235 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
236 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
237 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
238 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
240 test_cmp expect actual
243 test_expect_success 'changed commit with --stat diff option' '
244 git range-diff --no-color --stat topic...changed >actual &&
245 cat >expect <<-EOF &&
246 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
248 1 file changed, 0 insertions(+), 0 deletions(-)
249 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
251 1 file changed, 0 insertions(+), 0 deletions(-)
252 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
254 1 file changed, 0 insertions(+), 0 deletions(-)
255 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
257 1 file changed, 0 insertions(+), 0 deletions(-)
259 test_cmp expect actual
262 test_expect_success 'changed commit with sm config' '
263 git range-diff --no-color --submodule=log topic...changed >actual &&
264 cat >expect <<-EOF &&
265 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
266 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
267 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
277 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
288 test_cmp expect actual
291 test_expect_success 'renamed file' '
292 git range-diff --no-color --submodule=log topic...renamed-file >actual &&
293 sed s/Z/\ /g >expect <<-EOF &&
294 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/
295 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/
297 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
299 Z ## Commit message ##
301 + s/4/A/ + rename file
304 + ## file => renamed-file ##
308 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/
310 Z ## Commit message ##
320 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/
322 Z ## Commit message ##
333 test_cmp expect actual
336 test_expect_success 'file with mode only change' '
337 git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
338 sed s/Z/\ /g >expect <<-EOF &&
339 1: fccce22 ! 1: 4d39cb3 s/4/A/
341 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
343 Z ## Commit message ##
345 + s/4/A/ + add other-file
354 + ## other-file (new) ##
355 2: 147e64e ! 2: 26c107f s/11/B/
357 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
359 Z ## Commit message ##
361 + s/11/B/ + mode change other-file
370 + ## other-file (mode change 100644 => 100755) ##
371 3: a63e992 = 3: 4c1e0f5 s/12/B/
373 test_cmp expect actual
376 test_expect_success 'file added and later removed' '
377 git range-diff --no-color --submodule=log topic...added-removed >actual &&
378 sed s/Z/\ /g >expect <<-EOF &&
379 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/
380 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/
382 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
384 Z ## Commit message ##
395 + ## new-file (new) ##
396 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/
398 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
400 Z ## Commit message ##
402 + s/11/B/ + remove file
411 + ## new-file (deleted) ##
412 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
414 test_cmp expect actual
417 test_expect_success 'no commits on one side' '
418 git commit --amend -m "new message" &&
419 git range-diff master HEAD@{1} HEAD
422 test_expect_success 'changed message' '
423 git range-diff --no-color topic...changed-message >actual &&
424 sed s/Z/\ /g >expect <<-EOF &&
425 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/
426 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/
428 Z ## Commit message ##
431 + Also a silly comment here!
436 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
437 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
439 test_cmp expect actual
442 test_expect_success 'dual-coloring' '
443 sed -e "s|^:||" >expect <<-EOF &&
444 :<YELLOW>1: $(test_oid c1) = 1: $(test_oid m1) s/5/A/<RESET>
445 :<RED>2: $(test_oid c2) <RESET><YELLOW>!<RESET><GREEN> 2: $(test_oid m2)<RESET><YELLOW> s/4/A/<RESET>
446 : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
447 : ## Commit message ##<RESET>
450 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
451 : <REVERSE><GREEN>+<RESET>
455 :<RED>3: $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3: $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET>
456 : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
460 : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
461 : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET>
465 :<RED>4: $(test_oid c4) <RESET><YELLOW>!<RESET><GREEN> 4: $(test_oid m4)<RESET><YELLOW> s/12/B/<RESET>
466 : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
467 : <CYAN> @@ file: A<RESET>
470 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
471 : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
476 git range-diff changed...changed-message --color --dual-color >actual.raw &&
477 test_decode_color >actual <actual.raw &&
478 test_cmp expect actual
481 for prev in topic master..topic
483 test_expect_success "format-patch --range-diff=$prev" '
484 git format-patch --cover-letter --range-diff=$prev \
485 master..unmodified >actual &&
486 test_when_finished "rm 000?-*" &&
487 test_line_count = 5 actual &&
488 test_i18ngrep "^Range-diff:$" 0000-* &&
489 grep "= 1: .* s/5/A" 0000-* &&
490 grep "= 2: .* s/4/A" 0000-* &&
491 grep "= 3: .* s/11/B" 0000-* &&
492 grep "= 4: .* s/12/B" 0000-*
496 test_expect_success 'format-patch --range-diff as commentary' '
497 git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
498 test_when_finished "rm 0001-*" &&
499 test_line_count = 1 actual &&
500 test_i18ngrep "^Range-diff:$" 0001-* &&
501 grep "> 1: .* new message" 0001-*
504 test_expect_success 'range-diff overrides diff.noprefix internally' '
505 git -c diff.noprefix=true range-diff HEAD^...
508 test_expect_success 'range-diff compares notes by default' '
509 git notes add -m "topic note" topic &&
510 git notes add -m "unmodified note" unmodified &&
511 test_when_finished git notes remove topic unmodified &&
512 git range-diff --no-color master..topic master..unmodified \
514 sed s/Z/\ /g >expect <<-EOF &&
515 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
516 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
517 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
518 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
529 test_cmp expect actual
532 test_expect_success 'range-diff with --no-notes' '
533 git notes add -m "topic note" topic &&
534 git notes add -m "unmodified note" unmodified &&
535 test_when_finished git notes remove topic unmodified &&
536 git range-diff --no-color --no-notes master..topic master..unmodified \
538 cat >expect <<-EOF &&
539 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
540 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
541 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
542 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
544 test_cmp expect actual
547 test_expect_success 'range-diff with multiple --notes' '
548 git notes --ref=note1 add -m "topic note1" topic &&
549 git notes --ref=note1 add -m "unmodified note1" unmodified &&
550 test_when_finished git notes --ref=note1 remove topic unmodified &&
551 git notes --ref=note2 add -m "topic note2" topic &&
552 git notes --ref=note2 add -m "unmodified note2" unmodified &&
553 test_when_finished git notes --ref=note2 remove topic unmodified &&
554 git range-diff --no-color --notes=note1 --notes=note2 master..topic master..unmodified \
556 sed s/Z/\ /g >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/
564 Z ## Notes (note1) ##
569 Z ## Notes (note2) ##
576 test_cmp expect actual
579 test_expect_success 'format-patch --range-diff does not compare notes by default' '
580 git notes add -m "topic note" topic &&
581 git notes add -m "unmodified note" unmodified &&
582 test_when_finished git notes remove topic unmodified &&
583 git format-patch --cover-letter --range-diff=$prev \
584 master..unmodified >actual &&
585 test_when_finished "rm 000?-*" &&
586 test_line_count = 5 actual &&
587 test_i18ngrep "^Range-diff:$" 0000-* &&
588 grep "= 1: .* s/5/A" 0000-* &&
589 grep "= 2: .* s/4/A" 0000-* &&
590 grep "= 3: .* s/11/B" 0000-* &&
591 grep "= 4: .* s/12/B" 0000-* &&
592 ! grep "Notes" 0000-* &&
596 test_expect_success 'format-patch --range-diff with --no-notes' '
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 --no-notes --cover-letter --range-diff=$prev \
601 master..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 --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 --notes --cover-letter --range-diff=$prev \
618 master..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 sed s/Z/\ /g >expect <<-EOF &&
637 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
638 test_cmp expect actual
641 test_expect_success 'format-patch --range-diff with format.notes config' '
642 git notes add -m "topic note" topic &&
643 git notes add -m "unmodified note" unmodified &&
644 test_when_finished git notes remove topic unmodified &&
645 test_config format.notes true &&
646 git format-patch --cover-letter --range-diff=$prev \
647 master..unmodified >actual &&
648 test_when_finished "rm 000?-*" &&
649 test_line_count = 5 actual &&
650 test_i18ngrep "^Range-diff:$" 0000-* &&
651 grep "= 1: .* s/5/A" 0000-* &&
652 grep "= 2: .* s/4/A" 0000-* &&
653 grep "= 3: .* s/11/B" 0000-* &&
654 grep "! 4: .* s/12/B" 0000-* &&
655 sed s/Z/\ /g >expect <<-EOF &&
666 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
667 test_cmp expect actual
670 test_expect_success 'format-patch --range-diff with multiple notes' '
671 git notes --ref=note1 add -m "topic note1" topic &&
672 git notes --ref=note1 add -m "unmodified note1" unmodified &&
673 test_when_finished git notes --ref=note1 remove topic unmodified &&
674 git notes --ref=note2 add -m "topic note2" topic &&
675 git notes --ref=note2 add -m "unmodified note2" unmodified &&
676 test_when_finished git notes --ref=note2 remove topic unmodified &&
677 git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
678 master..unmodified >actual &&
679 test_when_finished "rm 000?-*" &&
680 test_line_count = 5 actual &&
681 test_i18ngrep "^Range-diff:$" 0000-* &&
682 grep "= 1: .* s/5/A" 0000-* &&
683 grep "= 2: .* s/4/A" 0000-* &&
684 grep "= 3: .* s/11/B" 0000-* &&
685 grep "! 4: .* s/12/B" 0000-* &&
686 sed s/Z/\ /g >expect <<-EOF &&
690 Z ## Notes (note1) ##
695 Z ## Notes (note2) ##
702 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
703 test_cmp expect actual