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
37 t1_abbrev sha1:4de457d2c0
38 t2_abbrev sha1:fccce22f8c
39 t3_abbrev sha1:147e64ef53
40 t4_abbrev sha1:a63e992599
41 t1_abbrev sha256:b89f8b9092
42 t2_abbrev sha256:5f12aadf34
43 t3_abbrev sha256:ea8b273a6c
44 t4_abbrev sha256:14b73361fc
46 # unmodified (abbrev=10)
47 u1_abbrev sha1:35b9b25f76
48 u2_abbrev sha1:de345ab3de
49 u3_abbrev sha1:9af6654000
50 u4_abbrev sha1:2901f773f3
51 u1_abbrev sha256:e3731be242
52 u2_abbrev sha256:14fadf8cee
53 u3_abbrev sha256:736c4bcb44
54 u4_abbrev sha256:673e77d589
146 # Empty delimiter (included so lines match neatly)
152 test_expect_success
'simple A..B A..C (unmodified)' '
153 git range-diff --no-color main..topic main..unmodified \
155 cat >expect <<-EOF &&
156 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
157 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
158 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
159 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
161 test_cmp expect actual
164 test_expect_success
'simple B...C (unmodified)' '
165 git range-diff --no-color topic...unmodified >actual &&
166 # same "expect" as above
167 test_cmp expect actual
170 test_expect_success
'simple A B C (unmodified)' '
171 git range-diff --no-color main topic unmodified >actual &&
172 # same "expect" as above
173 test_cmp expect actual
176 test_expect_success
'simple A..B A..C (unmodified) with --abbrev' '
177 git range-diff --no-color --abbrev=10 main..topic main..unmodified \
179 cat >expect <<-EOF &&
180 1: $(test_oid t1_abbrev) = 1: $(test_oid u1_abbrev) s/5/A/
181 2: $(test_oid t2_abbrev) = 2: $(test_oid u2_abbrev) s/4/A/
182 3: $(test_oid t3_abbrev) = 3: $(test_oid u3_abbrev) s/11/B/
183 4: $(test_oid t4_abbrev) = 4: $(test_oid u4_abbrev) s/12/B/
185 test_cmp expect actual
188 test_expect_success
'A^! and A^-<n> (unmodified)' '
189 git range-diff --no-color topic^! unmodified^-1 >actual &&
190 cat >expect <<-EOF &&
191 1: $(test_oid t4) = 1: $(test_oid u4) s/12/B/
193 test_cmp expect actual
196 test_expect_success
'A^{/..} is not mistaken for a range' '
197 test_must_fail git range-diff topic^.. topic^{/..} -- 2>error &&
198 test_grep "not a commit range" error
201 test_expect_success
'trivial reordering' '
202 git range-diff --no-color main topic reordered >actual &&
203 cat >expect <<-EOF &&
204 1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/
205 3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/
206 4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/
207 2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/
209 test_cmp expect actual
212 test_expect_success
'removed a commit' '
213 git range-diff --no-color main topic removed >actual &&
214 cat >expect <<-EOF &&
215 1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/
216 2: $(test_oid t2) < -: $(test_oid __) s/4/A/
217 3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/
218 4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/
220 test_cmp expect actual
223 test_expect_success
'added a commit' '
224 git range-diff --no-color main topic added >actual &&
225 cat >expect <<-EOF &&
226 1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/
227 2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/
228 -: $(test_oid __) > 3: $(test_oid a3) s/6/A/
229 3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/
230 4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/
232 test_cmp expect actual
235 test_expect_success
'new base, A B C' '
236 git range-diff --no-color main topic rebased >actual &&
237 cat >expect <<-EOF &&
238 1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/
239 2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/
240 3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/
241 4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/
243 test_cmp expect actual
246 test_expect_success
'new base, B...C' '
247 # this syntax includes the commits from main!
248 git range-diff --no-color topic...rebased >actual &&
249 cat >expect <<-EOF &&
250 -: $(test_oid __) > 1: $(test_oid b5) unrelated
251 1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/
252 2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/
253 3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/
254 4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/
256 test_cmp expect actual
259 test_expect_success
'changed commit' '
260 git range-diff --no-color topic...changed >actual &&
261 cat >expect <<-EOF &&
262 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
263 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
264 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
274 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
285 test_cmp expect actual
288 test_expect_success
'changed commit with --no-patch diff option' '
289 git range-diff --no-color --no-patch topic...changed >actual &&
290 cat >expect <<-EOF &&
291 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
292 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
293 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
294 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
296 test_cmp expect actual
299 test_expect_success
'changed commit with --stat diff option' '
300 git range-diff --no-color --stat topic...changed >actual &&
301 cat >expect <<-EOF &&
302 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
303 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
304 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
306 1 file changed, 1 insertion(+), 1 deletion(-)
307 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
309 1 file changed, 1 insertion(+), 1 deletion(-)
311 test_cmp expect actual
314 test_expect_success
'changed commit with sm config' '
315 git range-diff --no-color --submodule=log topic...changed >actual &&
316 cat >expect <<-EOF &&
317 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
318 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
319 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
329 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
340 test_cmp expect actual
343 test_expect_success
'renamed file' '
344 git range-diff --no-color --submodule=log topic...renamed-file >actual &&
345 sed s/Z/\ /g >expect <<-EOF &&
346 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/
347 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/
349 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
351 Z ## Commit message ##
353 + s/4/A/ + rename file
356 + ## file => renamed-file ##
360 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/
362 Z ## Commit message ##
372 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/
374 Z ## Commit message ##
385 test_cmp expect actual
388 test_expect_success
'file with mode only change' '
389 git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
390 sed s/Z/\ /g >expect <<-EOF &&
391 1: $(test_oid t2) ! 1: $(test_oid o1) s/4/A/
393 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
395 Z ## Commit message ##
397 + s/4/A/ + add other-file
406 + ## other-file (new) ##
407 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/
409 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
411 Z ## Commit message ##
413 + s/11/B/ + mode change other-file
422 + ## other-file (mode change 100644 => 100755) ##
423 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/
425 test_cmp expect actual
428 test_expect_success
'file added and later removed' '
429 git range-diff --no-color --submodule=log topic...added-removed >actual &&
430 sed s/Z/\ /g >expect <<-EOF &&
431 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/
432 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/
434 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
436 Z ## Commit message ##
447 + ## new-file (new) ##
448 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/
450 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
452 Z ## Commit message ##
454 + s/11/B/ + remove file
463 + ## new-file (deleted) ##
464 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
466 test_cmp expect actual
469 test_expect_success
'no commits on one side' '
470 git commit --amend -m "new message" &&
471 git range-diff main HEAD@{1} HEAD
474 test_expect_success
'changed message' '
475 git range-diff --no-color topic...changed-message >actual &&
476 sed s/Z/\ /g >expect <<-EOF &&
477 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/
478 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/
480 Z ## Commit message ##
483 + Also a silly comment here!
488 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
489 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
491 test_cmp expect actual
494 test_expect_success
'dual-coloring' '
495 sed -e "s|^:||" >expect <<-EOF &&
496 :<YELLOW>1: $(test_oid c1) = 1: $(test_oid m1) s/5/A/<RESET>
497 :<RED>2: $(test_oid c2) <RESET><YELLOW>!<RESET><GREEN> 2: $(test_oid m2)<RESET><YELLOW> s/4/A/<RESET>
498 : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
499 : ## Commit message ##<RESET>
502 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
503 : <REVERSE><GREEN>+<RESET>
507 :<RED>3: $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3: $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET>
508 : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
512 : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
513 : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET>
517 :<RED>4: $(test_oid c4) <RESET><YELLOW>!<RESET><GREEN> 4: $(test_oid m4)<RESET><YELLOW> s/12/B/<RESET>
518 : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
519 : <CYAN> @@ file: A<RESET>
522 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
523 : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
528 git range-diff changed...changed-message --color --dual-color >actual.raw &&
529 test_decode_color >actual <actual.raw &&
530 test_cmp expect actual
533 for prev
in topic main..topic
535 test_expect_success
"format-patch --range-diff=$prev" '
536 git format-patch --cover-letter --range-diff=$prev \
537 main..unmodified >actual &&
538 test_when_finished "rm 000?-*" &&
539 test_line_count = 5 actual &&
540 test_grep "^Range-diff:$" 0000-* &&
541 grep "= 1: .* s/5/A" 0000-* &&
542 grep "= 2: .* s/4/A" 0000-* &&
543 grep "= 3: .* s/11/B" 0000-* &&
544 grep "= 4: .* s/12/B" 0000-*
548 test_expect_success
"--range-diff implies --cover-letter for multi-patch series" '
549 test_when_finished "rm -f v2-000?-*" &&
550 git format-patch -v2 --range-diff=topic main..unmodified &&
551 test_grep "^Range-diff against v1:$" v2-0000-cover-letter.patch
554 test_expect_success
"explicit --no-cover-letter defeats implied --cover-letter" '
555 test_when_finished "rm -f v2-000?-*" &&
556 test_must_fail git format-patch --no-cover-letter \
557 -v2 --range-diff=topic main..unmodified &&
558 test_must_fail git -c format.coverLetter=no format-patch \
559 -v2 --range-diff=topic main..unmodified
562 test_expect_success
'format-patch --range-diff as commentary' '
563 git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
564 test_when_finished "rm 0001-*" &&
565 test_line_count = 1 actual &&
566 test_grep "^Range-diff:$" 0001-* &&
567 grep "> 1: .* new message" 0001-*
570 test_expect_success
'format-patch --range-diff reroll-count with a non-integer' '
571 git format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&
572 test_when_finished "rm v2.9-0001-*" &&
573 test_line_count = 1 actual &&
574 test_grep "^Range-diff:$" v2.9-0001-* &&
575 grep "> 1: .* new message" v2.9-0001-*
578 test_expect_success
'format-patch --range-diff reroll-count with a integer' '
579 git format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&
580 test_when_finished "rm v2-0001-*" &&
581 test_line_count = 1 actual &&
582 test_grep "^Range-diff ..* v1:$" v2-0001-* &&
583 grep "> 1: .* new message" v2-0001-*
586 test_expect_success
'format-patch --range-diff with v0' '
587 git format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&
588 test_when_finished "rm v0-0001-*" &&
589 test_line_count = 1 actual &&
590 test_grep "^Range-diff:$" v0-0001-* &&
591 grep "> 1: .* new message" v0-0001-*
594 test_expect_success
'range-diff overrides diff.noprefix internally' '
595 git -c diff.noprefix=true range-diff HEAD^...
598 test_expect_success
'basic with modified format.pretty with suffix' '
599 git -c format.pretty="format:commit %H%d%n" range-diff \
600 main..topic main..unmodified
603 test_expect_success
'basic with modified format.pretty without "commit "' '
604 git -c format.pretty="format:%H%n" range-diff \
605 main..topic main..unmodified
608 test_expect_success
'range-diff compares notes by default' '
609 git notes add -m "topic note" topic &&
610 git notes add -m "unmodified note" unmodified &&
611 test_when_finished git notes remove topic unmodified &&
612 git range-diff --no-color main..topic main..unmodified \
614 sed s/Z/\ /g >expect <<-EOF &&
615 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
616 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
617 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
618 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
629 test_cmp expect actual
632 test_expect_success
'range-diff with --no-notes' '
633 git notes add -m "topic note" topic &&
634 git notes add -m "unmodified note" unmodified &&
635 test_when_finished git notes remove topic unmodified &&
636 git range-diff --no-color --no-notes main..topic main..unmodified \
638 cat >expect <<-EOF &&
639 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
640 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
641 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
642 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
644 test_cmp expect actual
647 test_expect_success
'range-diff with multiple --notes' '
648 git notes --ref=note1 add -m "topic note1" topic &&
649 git notes --ref=note1 add -m "unmodified note1" unmodified &&
650 test_when_finished git notes --ref=note1 remove topic unmodified &&
651 git notes --ref=note2 add -m "topic note2" topic &&
652 git notes --ref=note2 add -m "unmodified note2" unmodified &&
653 test_when_finished git notes --ref=note2 remove topic unmodified &&
654 git range-diff --no-color --notes=note1 --notes=note2 main..topic main..unmodified \
656 sed s/Z/\ /g >expect <<-EOF &&
657 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
658 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
659 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
660 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
664 Z ## Notes (note1) ##
669 Z ## Notes (note2) ##
676 test_cmp expect actual
679 # `range-diff` should act like `log` with regards to notes
680 test_expect_success
'range-diff with --notes=custom does not show default notes' '
681 git notes add -m "topic note" topic &&
682 git notes add -m "unmodified note" unmodified &&
683 git notes --ref=custom add -m "topic note" topic &&
684 git notes --ref=custom add -m "unmodified note" unmodified &&
685 test_when_finished git notes remove topic unmodified &&
686 test_when_finished git notes --ref=custom remove topic unmodified &&
687 git range-diff --notes=custom main..topic main..unmodified \
689 ! grep "## Notes ##" actual &&
690 grep "## Notes (custom) ##" actual
693 test_expect_success
'format-patch --range-diff does not compare notes by default' '
694 git notes add -m "topic note" topic &&
695 git notes add -m "unmodified note" unmodified &&
696 test_when_finished git notes remove topic unmodified &&
697 git format-patch --cover-letter --range-diff=$prev \
698 main..unmodified >actual &&
699 test_when_finished "rm 000?-*" &&
700 test_line_count = 5 actual &&
701 test_grep "^Range-diff:$" 0000-* &&
702 grep "= 1: .* s/5/A" 0000-* &&
703 grep "= 2: .* s/4/A" 0000-* &&
704 grep "= 3: .* s/11/B" 0000-* &&
705 grep "= 4: .* s/12/B" 0000-* &&
706 ! grep "Notes" 0000-* &&
710 test_expect_success
'format-patch --notes=custom --range-diff only compares custom notes' '
711 git notes add -m "topic note" topic &&
712 git notes --ref=custom add -m "topic note (custom)" topic &&
713 git notes add -m "unmodified note" unmodified &&
714 git notes --ref=custom add -m "unmodified note (custom)" unmodified &&
715 test_when_finished git notes remove topic unmodified &&
716 test_when_finished git notes --ref=custom remove topic unmodified &&
717 git format-patch --notes=custom --cover-letter --range-diff=$prev \
718 main..unmodified >actual &&
719 test_when_finished "rm 000?-*" &&
720 grep "## Notes (custom) ##" 0000-* &&
721 ! grep "## Notes ##" 0000-*
724 test_expect_success
'format-patch --range-diff with --no-notes' '
725 git notes add -m "topic note" topic &&
726 git notes add -m "unmodified note" unmodified &&
727 test_when_finished git notes remove topic unmodified &&
728 git format-patch --no-notes --cover-letter --range-diff=$prev \
729 main..unmodified >actual &&
730 test_when_finished "rm 000?-*" &&
731 test_line_count = 5 actual &&
732 test_grep "^Range-diff:$" 0000-* &&
733 grep "= 1: .* s/5/A" 0000-* &&
734 grep "= 2: .* s/4/A" 0000-* &&
735 grep "= 3: .* s/11/B" 0000-* &&
736 grep "= 4: .* s/12/B" 0000-* &&
737 ! grep "Notes" 0000-* &&
741 test_expect_success
'format-patch --range-diff with --notes' '
742 git notes add -m "topic note" topic &&
743 git notes add -m "unmodified note" unmodified &&
744 test_when_finished git notes remove topic unmodified &&
745 git format-patch --notes --cover-letter --range-diff=$prev \
746 main..unmodified >actual &&
747 test_when_finished "rm 000?-*" &&
748 test_line_count = 5 actual &&
749 test_grep "^Range-diff:$" 0000-* &&
750 grep "= 1: .* s/5/A" 0000-* &&
751 grep "= 2: .* s/4/A" 0000-* &&
752 grep "= 3: .* s/11/B" 0000-* &&
753 grep "! 4: .* s/12/B" 0000-* &&
754 sed s/Z/\ /g >expect <<-EOF &&
765 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
766 test_cmp expect actual
769 test_expect_success
'format-patch --range-diff with format.notes config' '
770 git notes add -m "topic note" topic &&
771 git notes add -m "unmodified note" unmodified &&
772 test_when_finished git notes remove topic unmodified &&
773 test_config format.notes true &&
774 git format-patch --cover-letter --range-diff=$prev \
775 main..unmodified >actual &&
776 test_when_finished "rm 000?-*" &&
777 test_line_count = 5 actual &&
778 test_grep "^Range-diff:$" 0000-* &&
779 grep "= 1: .* s/5/A" 0000-* &&
780 grep "= 2: .* s/4/A" 0000-* &&
781 grep "= 3: .* s/11/B" 0000-* &&
782 grep "! 4: .* s/12/B" 0000-* &&
783 sed s/Z/\ /g >expect <<-EOF &&
794 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
795 test_cmp expect actual
798 test_expect_success
'format-patch --range-diff with multiple notes' '
799 git notes --ref=note1 add -m "topic note1" topic &&
800 git notes --ref=note1 add -m "unmodified note1" unmodified &&
801 test_when_finished git notes --ref=note1 remove topic unmodified &&
802 git notes --ref=note2 add -m "topic note2" topic &&
803 git notes --ref=note2 add -m "unmodified note2" unmodified &&
804 test_when_finished git notes --ref=note2 remove topic unmodified &&
805 git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
806 main..unmodified >actual &&
807 test_when_finished "rm 000?-*" &&
808 test_line_count = 5 actual &&
809 test_grep "^Range-diff:$" 0000-* &&
810 grep "= 1: .* s/5/A" 0000-* &&
811 grep "= 2: .* s/4/A" 0000-* &&
812 grep "= 3: .* s/11/B" 0000-* &&
813 grep "! 4: .* s/12/B" 0000-* &&
814 sed s/Z/\ /g >expect <<-EOF &&
818 Z ## Notes (note1) ##
823 Z ## Notes (note2) ##
830 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
831 test_cmp expect actual
834 test_expect_success
'--left-only/--right-only' '
835 git switch --orphan left-right &&
837 test_commit unmatched &&
838 test_commit common &&
839 git switch -C left-right first &&
840 git cherry-pick common &&
842 git range-diff -s --left-only ...common >actual &&
843 head_oid=$(git rev-parse --short HEAD) &&
844 common_oid=$(git rev-parse --short common) &&
845 echo "1: $head_oid = 2: $common_oid common" >expect &&
846 test_cmp expect actual
849 test_expect_success
'ranges with pathspecs' '
850 git range-diff topic...mode-only-change -- other-file >actual &&
851 test_line_count = 2 actual &&
852 topic_oid=$(git rev-parse --short topic) &&
853 mode_change_oid=$(git rev-parse --short mode-only-change^) &&
854 file_change_oid=$(git rev-parse --short mode-only-change) &&
855 grep "$mode_change_oid" actual &&
856 ! grep "$file_change_oid" actual &&
857 ! grep "$topic_oid" actual
860 test_expect_success
'submodule changes are shown irrespective of diff.submodule' '
862 test_commit -C sub-repo sub-first &&
863 sub_oid1=$(git -C sub-repo rev-parse HEAD) &&
864 test_commit -C sub-repo sub-second &&
865 sub_oid2=$(git -C sub-repo rev-parse HEAD) &&
866 test_commit -C sub-repo sub-third &&
867 sub_oid3=$(git -C sub-repo rev-parse HEAD) &&
869 git checkout -b main-sub topic &&
870 git -c protocol.file.allow=always submodule add ./sub-repo sub &&
871 git -C sub checkout --detach sub-first &&
872 git commit -m "add sub" sub &&
873 sup_oid1=$(git rev-parse --short HEAD) &&
874 git checkout -b topic-sub &&
875 git -C sub checkout sub-second &&
876 git commit -m "change sub" sub &&
877 sup_oid2=$(git rev-parse --short HEAD) &&
878 git checkout -b modified-sub main-sub &&
879 git -C sub checkout sub-third &&
880 git commit -m "change sub" sub &&
881 sup_oid3=$(git rev-parse --short HEAD) &&
882 sup_oid0=$(test_oid __) &&
884 test_config diff.submodule log &&
885 git range-diff topic topic-sub modified-sub >actual &&
886 cat >expect <<-EOF &&
887 1: $sup_oid1 = 1: $sup_oid1 add sub
888 2: $sup_oid2 < -: $sup_oid0 change sub
889 -: $sup_oid0 > 2: $sup_oid3 change sub
891 test_cmp expect actual &&
892 test_config diff.submodule diff &&
893 git range-diff topic topic-sub modified-sub >actual &&
894 git range-diff --creation-factor=100 topic topic-sub modified-sub >actual &&
895 cat >expect <<-EOF &&
896 1: $sup_oid1 = 1: $sup_oid1 add sub
897 2: $sup_oid2 ! 2: $sup_oid3 change sub
901 -Subproject commit $sub_oid1
902 -+Subproject commit $sub_oid2
903 ++Subproject commit $sub_oid3
905 test_cmp expect actual &&
906 test_config diff.submodule diff &&
907 git range-diff --creation-factor=100 topic topic-sub modified-sub >actual &&
908 test_cmp expect actual