3 test_description
='range-diff tests'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 # Note that because of the range-diff's heuristics, test_commit does more
12 # harm than good. We need some real history.
14 test_expect_success
'setup' '
15 git fast-import <"$TEST_DIRECTORY"/t3206/history.export &&
16 test_oid_cache <<-\EOF
38 t1_abbrev sha1:4de457d2c0
39 t2_abbrev sha1:fccce22f8c
40 t3_abbrev sha1:147e64ef53
41 t4_abbrev sha1:a63e992599
42 t1_abbrev sha256:b89f8b9092
43 t2_abbrev sha256:5f12aadf34
44 t3_abbrev sha256:ea8b273a6c
45 t4_abbrev sha256:14b73361fc
47 # unmodified (abbrev=10)
48 u1_abbrev sha1:35b9b25f76
49 u2_abbrev sha1:de345ab3de
50 u3_abbrev sha1:9af6654000
51 u4_abbrev sha1:2901f773f3
52 u1_abbrev sha256:e3731be242
53 u2_abbrev sha256:14fadf8cee
54 u3_abbrev sha256:736c4bcb44
55 u4_abbrev sha256:673e77d589
147 # Empty delimiter (included so lines match neatly)
153 test_expect_success
'simple A..B A..C (unmodified)' '
154 git range-diff --no-color main..topic main..unmodified \
156 cat >expect <<-EOF &&
157 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
158 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
159 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
160 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
162 test_cmp expect actual
165 test_expect_success
'simple B...C (unmodified)' '
166 git range-diff --no-color topic...unmodified >actual &&
167 # same "expect" as above
168 test_cmp expect actual
171 test_expect_success
'simple A B C (unmodified)' '
172 git range-diff --no-color main topic unmodified >actual &&
173 # same "expect" as above
174 test_cmp expect actual
177 test_expect_success
'simple A..B A..C (unmodified) with --abbrev' '
178 git range-diff --no-color --abbrev=10 main..topic main..unmodified \
180 cat >expect <<-EOF &&
181 1: $(test_oid t1_abbrev) = 1: $(test_oid u1_abbrev) s/5/A/
182 2: $(test_oid t2_abbrev) = 2: $(test_oid u2_abbrev) s/4/A/
183 3: $(test_oid t3_abbrev) = 3: $(test_oid u3_abbrev) s/11/B/
184 4: $(test_oid t4_abbrev) = 4: $(test_oid u4_abbrev) s/12/B/
186 test_cmp expect actual
189 test_expect_success
'A^! and A^-<n> (unmodified)' '
190 git range-diff --no-color topic^! unmodified^-1 >actual &&
191 cat >expect <<-EOF &&
192 1: $(test_oid t4) = 1: $(test_oid u4) s/12/B/
194 test_cmp expect actual
197 test_expect_success
'A^{/..} is not mistaken for a range' '
198 test_must_fail git range-diff topic^.. topic^{/..} -- 2>error &&
199 test_grep "not a commit range" error
202 test_expect_success
'trivial reordering' '
203 git range-diff --no-color main topic reordered >actual &&
204 cat >expect <<-EOF &&
205 1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/
206 3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/
207 4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/
208 2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/
210 test_cmp expect actual
213 test_expect_success
'removed a commit' '
214 git range-diff --no-color main topic removed >actual &&
215 cat >expect <<-EOF &&
216 1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/
217 2: $(test_oid t2) < -: $(test_oid __) s/4/A/
218 3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/
219 4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/
221 test_cmp expect actual
224 test_expect_success
'added a commit' '
225 git range-diff --no-color main topic added >actual &&
226 cat >expect <<-EOF &&
227 1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/
228 2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/
229 -: $(test_oid __) > 3: $(test_oid a3) s/6/A/
230 3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/
231 4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/
233 test_cmp expect actual
236 test_expect_success
'new base, A B C' '
237 git range-diff --no-color main topic rebased >actual &&
238 cat >expect <<-EOF &&
239 1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/
240 2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/
241 3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/
242 4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/
244 test_cmp expect actual
247 test_expect_success
'new base, B...C' '
248 # this syntax includes the commits from main!
249 git range-diff --no-color topic...rebased >actual &&
250 cat >expect <<-EOF &&
251 -: $(test_oid __) > 1: $(test_oid b5) unrelated
252 1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/
253 2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/
254 3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/
255 4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/
257 test_cmp expect actual
260 test_expect_success
'changed commit' '
261 git range-diff --no-color topic...changed >actual &&
262 cat >expect <<-EOF &&
263 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
264 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
265 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
275 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
286 test_cmp expect actual
289 test_expect_success
'changed commit with --no-patch diff option' '
290 git range-diff --no-color --no-patch topic...changed >actual &&
291 cat >expect <<-EOF &&
292 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
293 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
294 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
295 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
297 test_cmp expect actual
300 test_expect_success
'changed commit with --stat diff option' '
301 git range-diff --no-color --stat topic...changed >actual &&
302 cat >expect <<-EOF &&
303 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
304 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
305 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
307 1 file changed, 1 insertion(+), 1 deletion(-)
308 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
310 1 file changed, 1 insertion(+), 1 deletion(-)
312 test_cmp expect actual
315 test_expect_success
'changed commit with sm config' '
316 git range-diff --no-color --submodule=log topic...changed >actual &&
317 cat >expect <<-EOF &&
318 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
319 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
320 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
330 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
341 test_cmp expect actual
344 test_expect_success
'renamed file' '
345 git range-diff --no-color --submodule=log topic...renamed-file >actual &&
346 sed s/Z/\ /g >expect <<-EOF &&
347 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/
348 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/
350 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
352 Z ## Commit message ##
354 + s/4/A/ + rename file
357 + ## file => renamed-file ##
361 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/
363 Z ## Commit message ##
373 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/
375 Z ## Commit message ##
386 test_cmp expect actual
389 test_expect_success
'file with mode only change' '
390 git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
391 sed s/Z/\ /g >expect <<-EOF &&
392 1: $(test_oid t2) ! 1: $(test_oid o1) s/4/A/
394 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
396 Z ## Commit message ##
398 + s/4/A/ + add other-file
407 + ## other-file (new) ##
408 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/
410 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
412 Z ## Commit message ##
414 + s/11/B/ + mode change other-file
423 + ## other-file (mode change 100644 => 100755) ##
424 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/
426 test_cmp expect actual
429 test_expect_success
'file added and later removed' '
430 git range-diff --no-color --submodule=log topic...added-removed >actual &&
431 sed s/Z/\ /g >expect <<-EOF &&
432 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/
433 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/
435 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
437 Z ## Commit message ##
448 + ## new-file (new) ##
449 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/
451 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
453 Z ## Commit message ##
455 + s/11/B/ + remove file
464 + ## new-file (deleted) ##
465 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
467 test_cmp expect actual
470 test_expect_success
'no commits on one side' '
471 git commit --amend -m "new message" &&
472 git range-diff main HEAD@{1} HEAD
475 test_expect_success
'changed message' '
476 git range-diff --no-color topic...changed-message >actual &&
477 sed s/Z/\ /g >expect <<-EOF &&
478 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/
479 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/
481 Z ## Commit message ##
484 + Also a silly comment here!
489 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
490 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
492 test_cmp expect actual
495 test_expect_success
'dual-coloring' '
496 sed -e "s|^:||" >expect <<-EOF &&
497 :<YELLOW>1: $(test_oid c1) = 1: $(test_oid m1) s/5/A/<RESET>
498 :<RED>2: $(test_oid c2) <RESET><YELLOW>!<RESET><GREEN> 2: $(test_oid m2)<RESET><YELLOW> s/4/A/<RESET>
499 : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
500 : ## Commit message ##<RESET>
503 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
504 : <REVERSE><GREEN>+<RESET>
508 :<RED>3: $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3: $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET>
509 : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
513 : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
514 : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET>
518 :<RED>4: $(test_oid c4) <RESET><YELLOW>!<RESET><GREEN> 4: $(test_oid m4)<RESET><YELLOW> s/12/B/<RESET>
519 : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
520 : <CYAN> @@ file: A<RESET>
523 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
524 : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
529 git range-diff changed...changed-message --color --dual-color >actual.raw &&
530 test_decode_color >actual <actual.raw &&
531 test_cmp expect actual
534 for prev
in topic main..topic
536 test_expect_success
"format-patch --range-diff=$prev" '
537 test_when_finished "rm -f 000?-*" &&
538 git format-patch --cover-letter --range-diff=$prev \
539 main..unmodified >actual &&
540 test_line_count = 5 actual &&
541 test_grep "^Range-diff:$" 0000-* &&
542 grep "= 1: .* s/5/A" 0000-* &&
543 grep "= 2: .* s/4/A" 0000-* &&
544 grep "= 3: .* s/11/B" 0000-* &&
545 grep "= 4: .* s/12/B" 0000-*
549 test_expect_success
"--range-diff implies --cover-letter for multi-patch series" '
550 test_when_finished "rm -f v2-000?-*" &&
551 git format-patch -v2 --range-diff=topic main..unmodified &&
552 test_grep "^Range-diff against v1:$" v2-0000-cover-letter.patch
555 test_expect_success
"explicit --no-cover-letter defeats implied --cover-letter" '
556 test_when_finished "rm -f v2-000?-*" &&
557 test_must_fail git format-patch --no-cover-letter \
558 -v2 --range-diff=topic main..unmodified &&
559 test_must_fail git -c format.coverLetter=no format-patch \
560 -v2 --range-diff=topic main..unmodified
563 test_expect_success
'format-patch --range-diff as commentary' '
564 test_when_finished "rm -f 0001-*" &&
565 git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
566 test_line_count = 1 actual &&
567 test_grep "^Range-diff:$" 0001-* &&
568 grep "> 1: .* new message" 0001-*
571 test_expect_success
'format-patch --range-diff reroll-count with a non-integer' '
572 test_when_finished "rm -f v2.9-0001-*" &&
573 git format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&
574 test_line_count = 1 actual &&
575 test_grep "^Range-diff:$" v2.9-0001-* &&
576 grep "> 1: .* new message" v2.9-0001-*
579 test_expect_success
'format-patch --range-diff reroll-count with a integer' '
580 test_when_finished "rm -f v2-0001-*" &&
581 git format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&
582 test_line_count = 1 actual &&
583 test_grep "^Range-diff ..* v1:$" v2-0001-* &&
584 grep "> 1: .* new message" v2-0001-*
587 test_expect_success
'format-patch --range-diff with v0' '
588 test_when_finished "rm -f v0-0001-*" &&
589 git format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&
590 test_line_count = 1 actual &&
591 test_grep "^Range-diff:$" v0-0001-* &&
592 grep "> 1: .* new message" v0-0001-*
595 test_expect_success
'range-diff overrides diff.noprefix internally' '
596 git -c diff.noprefix=true range-diff HEAD^...
599 test_expect_success
'basic with modified format.pretty with suffix' '
600 git -c format.pretty="format:commit %H%d%n" range-diff \
601 main..topic main..unmodified
604 test_expect_success
'basic with modified format.pretty without "commit "' '
605 git -c format.pretty="format:%H%n" range-diff \
606 main..topic main..unmodified
609 test_expect_success
'range-diff compares notes by default' '
610 test_when_finished "git notes remove topic unmodified || :" &&
611 git notes add -m "topic note" topic &&
612 git notes add -m "unmodified note" unmodified &&
613 git range-diff --no-color main..topic main..unmodified \
615 sed s/Z/\ /g >expect <<-EOF &&
616 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
617 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
618 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
619 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
630 test_cmp expect actual
633 test_expect_success
'range-diff with --no-notes' '
634 test_when_finished "git notes remove topic unmodified || :" &&
635 git notes add -m "topic note" topic &&
636 git notes add -m "unmodified note" unmodified &&
637 git range-diff --no-color --no-notes main..topic main..unmodified \
639 cat >expect <<-EOF &&
640 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
641 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
642 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
643 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
645 test_cmp expect actual
648 test_expect_success
'range-diff with multiple --notes' '
649 test_when_finished "git notes --ref=note1 remove topic unmodified || :" &&
650 git notes --ref=note1 add -m "topic note1" topic &&
651 git notes --ref=note1 add -m "unmodified note1" unmodified &&
652 test_when_finished "git notes --ref=note2 remove topic unmodified || :" &&
653 git notes --ref=note2 add -m "topic note2" topic &&
654 git notes --ref=note2 add -m "unmodified note2" unmodified &&
655 git range-diff --no-color --notes=note1 --notes=note2 main..topic main..unmodified \
657 sed s/Z/\ /g >expect <<-EOF &&
658 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
659 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
660 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
661 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
665 Z ## Notes (note1) ##
670 Z ## Notes (note2) ##
677 test_cmp expect actual
680 # `range-diff` should act like `log` with regards to notes
681 test_expect_success
'range-diff with --notes=custom does not show default notes' '
682 test_when_finished "git notes remove topic unmodified || :" &&
683 git notes add -m "topic note" topic &&
684 git notes add -m "unmodified note" unmodified &&
685 test_when_finished "git notes --ref=custom remove topic unmodified || :" &&
686 git notes --ref=custom add -m "topic note" topic &&
687 git notes --ref=custom add -m "unmodified note" unmodified &&
688 git range-diff --notes=custom main..topic main..unmodified \
690 ! grep "## Notes ##" actual &&
691 grep "## Notes (custom) ##" actual
694 test_expect_success
'format-patch --range-diff does not compare notes by default' '
695 test_when_finished "git notes remove topic unmodified || :" &&
696 git notes add -m "topic note" topic &&
697 git notes add -m "unmodified note" unmodified &&
698 test_when_finished "rm -f 000?-*" &&
699 git format-patch --cover-letter --range-diff=$prev \
700 main..unmodified >actual &&
701 test_line_count = 5 actual &&
702 test_grep "^Range-diff:$" 0000-* &&
703 grep "= 1: .* s/5/A" 0000-* &&
704 grep "= 2: .* s/4/A" 0000-* &&
705 grep "= 3: .* s/11/B" 0000-* &&
706 grep "= 4: .* s/12/B" 0000-* &&
707 ! grep "Notes" 0000-* &&
711 test_expect_success
'format-patch --notes=custom --range-diff only compares custom notes' '
712 test_when_finished "git notes remove topic unmodified || :" &&
713 git notes add -m "topic note" topic &&
714 git notes add -m "unmodified note" unmodified &&
715 test_when_finished "git notes --ref=custom remove topic unmodified || :" &&
716 git notes --ref=custom add -m "topic note (custom)" topic &&
717 git notes --ref=custom add -m "unmodified note (custom)" unmodified &&
718 test_when_finished "rm -f 000?-*" &&
719 git format-patch --notes=custom --cover-letter --range-diff=$prev \
720 main..unmodified >actual &&
721 grep "## Notes (custom) ##" 0000-* &&
722 ! grep "## Notes ##" 0000-*
725 test_expect_success
'format-patch --range-diff with --no-notes' '
726 test_when_finished "git notes remove topic unmodified || :" &&
727 git notes add -m "topic note" topic &&
728 git notes add -m "unmodified note" unmodified &&
729 test_when_finished "rm -f 000?-*" &&
730 git format-patch --no-notes --cover-letter --range-diff=$prev \
731 main..unmodified >actual &&
732 test_line_count = 5 actual &&
733 test_grep "^Range-diff:$" 0000-* &&
734 grep "= 1: .* s/5/A" 0000-* &&
735 grep "= 2: .* s/4/A" 0000-* &&
736 grep "= 3: .* s/11/B" 0000-* &&
737 grep "= 4: .* s/12/B" 0000-* &&
738 ! grep "Notes" 0000-* &&
742 test_expect_success
'format-patch --range-diff with --notes' '
743 test_when_finished "git notes remove topic unmodified || :" &&
744 git notes add -m "topic note" topic &&
745 git notes add -m "unmodified note" unmodified &&
746 test_when_finished "rm -f 000?-*" &&
747 git format-patch --notes --cover-letter --range-diff=$prev \
748 main..unmodified >actual &&
749 test_line_count = 5 actual &&
750 test_grep "^Range-diff:$" 0000-* &&
751 grep "= 1: .* s/5/A" 0000-* &&
752 grep "= 2: .* s/4/A" 0000-* &&
753 grep "= 3: .* s/11/B" 0000-* &&
754 grep "! 4: .* s/12/B" 0000-* &&
755 sed s/Z/\ /g >expect <<-EOF &&
766 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
767 test_cmp expect actual
770 test_expect_success
'format-patch --range-diff with format.notes config' '
771 test_when_finished "git notes remove topic unmodified || :" &&
772 git notes add -m "topic note" topic &&
773 git notes add -m "unmodified note" unmodified &&
774 test_config format.notes true &&
775 test_when_finished "rm -f 000?-*" &&
776 git format-patch --cover-letter --range-diff=$prev \
777 main..unmodified >actual &&
778 test_line_count = 5 actual &&
779 test_grep "^Range-diff:$" 0000-* &&
780 grep "= 1: .* s/5/A" 0000-* &&
781 grep "= 2: .* s/4/A" 0000-* &&
782 grep "= 3: .* s/11/B" 0000-* &&
783 grep "! 4: .* s/12/B" 0000-* &&
784 sed s/Z/\ /g >expect <<-EOF &&
795 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
796 test_cmp expect actual
799 test_expect_success
'format-patch --range-diff with multiple notes' '
800 test_when_finished "git notes --ref=note1 remove topic unmodified || :" &&
801 git notes --ref=note1 add -m "topic note1" topic &&
802 git notes --ref=note1 add -m "unmodified note1" unmodified &&
803 test_when_finished "git notes --ref=note2 remove topic unmodified || :" &&
804 git notes --ref=note2 add -m "topic note2" topic &&
805 git notes --ref=note2 add -m "unmodified note2" unmodified &&
806 test_when_finished "rm -f 000?-*" &&
807 git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
808 main..unmodified >actual &&
809 test_line_count = 5 actual &&
810 test_grep "^Range-diff:$" 0000-* &&
811 grep "= 1: .* s/5/A" 0000-* &&
812 grep "= 2: .* s/4/A" 0000-* &&
813 grep "= 3: .* s/11/B" 0000-* &&
814 grep "! 4: .* s/12/B" 0000-* &&
815 sed s/Z/\ /g >expect <<-EOF &&
819 Z ## Notes (note1) ##
824 Z ## Notes (note2) ##
831 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
832 test_cmp expect actual
835 test_expect_success
'--left-only/--right-only' '
836 git switch --orphan left-right &&
838 test_commit unmatched &&
839 test_commit common &&
840 git switch -C left-right first &&
841 git cherry-pick common &&
843 git range-diff -s --left-only ...common >actual &&
844 head_oid=$(git rev-parse --short HEAD) &&
845 common_oid=$(git rev-parse --short common) &&
846 echo "1: $head_oid = 2: $common_oid common" >expect &&
847 test_cmp expect actual
850 test_expect_success
'ranges with pathspecs' '
851 git range-diff topic...mode-only-change -- other-file >actual &&
852 test_line_count = 2 actual &&
853 topic_oid=$(git rev-parse --short topic) &&
854 mode_change_oid=$(git rev-parse --short mode-only-change^) &&
855 file_change_oid=$(git rev-parse --short mode-only-change) &&
856 grep "$mode_change_oid" actual &&
857 ! grep "$file_change_oid" actual &&
858 ! grep "$topic_oid" actual
861 test_expect_success
'submodule changes are shown irrespective of diff.submodule' '
863 test_commit -C sub-repo sub-first &&
864 sub_oid1=$(git -C sub-repo rev-parse HEAD) &&
865 test_commit -C sub-repo sub-second &&
866 sub_oid2=$(git -C sub-repo rev-parse HEAD) &&
867 test_commit -C sub-repo sub-third &&
868 sub_oid3=$(git -C sub-repo rev-parse HEAD) &&
870 git checkout -b main-sub topic &&
871 git -c protocol.file.allow=always submodule add ./sub-repo sub &&
872 git -C sub checkout --detach sub-first &&
873 git commit -m "add sub" sub &&
874 sup_oid1=$(git rev-parse --short HEAD) &&
875 git checkout -b topic-sub &&
876 git -C sub checkout sub-second &&
877 git commit -m "change sub" sub &&
878 sup_oid2=$(git rev-parse --short HEAD) &&
879 git checkout -b modified-sub main-sub &&
880 git -C sub checkout sub-third &&
881 git commit -m "change sub" sub &&
882 sup_oid3=$(git rev-parse --short HEAD) &&
883 sup_oid0=$(test_oid __) &&
885 test_config diff.submodule log &&
886 git range-diff topic topic-sub modified-sub >actual &&
887 cat >expect <<-EOF &&
888 1: $sup_oid1 = 1: $sup_oid1 add sub
889 2: $sup_oid2 < -: $sup_oid0 change sub
890 -: $sup_oid0 > 2: $sup_oid3 change sub
892 test_cmp expect actual &&
893 test_config diff.submodule diff &&
894 git range-diff topic topic-sub modified-sub >actual &&
895 git range-diff --creation-factor=100 topic topic-sub modified-sub >actual &&
896 cat >expect <<-EOF &&
897 1: $sup_oid1 = 1: $sup_oid1 add sub
898 2: $sup_oid2 ! 2: $sup_oid3 change sub
902 -Subproject commit $sub_oid1
903 -+Subproject commit $sub_oid2
904 ++Subproject commit $sub_oid3
906 test_cmp expect actual &&
907 test_config diff.submodule diff &&
908 git range-diff --creation-factor=100 topic topic-sub modified-sub >actual &&
909 test_cmp expect actual