summaryrefslogtreecommitdiff
path: root/t/t3206-range-diff.sh
diff options
context:
space:
mode:
Diffstat (limited to 't/t3206-range-diff.sh')
-rwxr-xr-xt/t3206-range-diff.sh503
1 files changed, 446 insertions, 57 deletions
diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
index 0579cd9..7b05bf3 100755
--- a/t/t3206-range-diff.sh
+++ b/t/t3206-range-diff.sh
@@ -2,14 +2,17 @@
test_description='range-diff tests'
+GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
+export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
+
. ./test-lib.sh
# Note that because of the range-diff's heuristics, test_commit does more
# harm than good. We need some real history.
test_expect_success 'setup' '
- git fast-import < "$TEST_DIRECTORY"/t3206/history.export &&
- test_oid_cache <<-EOF
+ git fast-import <"$TEST_DIRECTORY"/t3206/history.export &&
+ test_oid_cache <<-\EOF
# topic
t1 sha1:4de457d
t2 sha1:fccce22
@@ -30,6 +33,26 @@ test_expect_success 'setup' '
u3 sha256:736c4bc
u4 sha256:673e77d
+ # topic (abbrev=10)
+ t1_abbrev sha1:4de457d2c0
+ t2_abbrev sha1:fccce22f8c
+ t3_abbrev sha1:147e64ef53
+ t4_abbrev sha1:a63e992599
+ t1_abbrev sha256:b89f8b9092
+ t2_abbrev sha256:5f12aadf34
+ t3_abbrev sha256:ea8b273a6c
+ t4_abbrev sha256:14b73361fc
+
+ # unmodified (abbrev=10)
+ u1_abbrev sha1:35b9b25f76
+ u2_abbrev sha1:de345ab3de
+ u3_abbrev sha1:9af6654000
+ u4_abbrev sha1:2901f773f3
+ u1_abbrev sha256:e3731be242
+ u2_abbrev sha256:14fadf8cee
+ u3_abbrev sha256:736c4bcb44
+ u4_abbrev sha256:673e77d589
+
# reordered
r1 sha1:aca177a
r2 sha1:14ad629
@@ -102,6 +125,14 @@ test_expect_success 'setup' '
n3 sha256:3b0a644
n4 sha256:e461653
+ # mode change
+ o1 sha1:4d39cb3
+ o2 sha1:26c107f
+ o3 sha1:4c1e0f5
+ o1 sha256:d0dd598
+ o2 sha256:c4a279e
+ o3 sha256:78459d7
+
# added and removed
s1 sha1:096b1ba
s2 sha1:d92e698
@@ -119,90 +150,115 @@ test_expect_success 'setup' '
'
test_expect_success 'simple A..B A..C (unmodified)' '
- git range-diff --no-color master..topic master..unmodified \
+ git range-diff --no-color main..topic main..unmodified \
>actual &&
- cat >expected <<-EOF &&
+ cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'simple B...C (unmodified)' '
git range-diff --no-color topic...unmodified >actual &&
- # same "expected" as above
- test_cmp expected actual
+ # same "expect" as above
+ test_cmp expect actual
'
test_expect_success 'simple A B C (unmodified)' '
- git range-diff --no-color master topic unmodified >actual &&
- # same "expected" as above
- test_cmp expected actual
+ git range-diff --no-color main topic unmodified >actual &&
+ # same "expect" as above
+ test_cmp expect actual
+'
+
+test_expect_success 'simple A..B A..C (unmodified) with --abbrev' '
+ git range-diff --no-color --abbrev=10 main..topic main..unmodified \
+ >actual &&
+ cat >expect <<-EOF &&
+ 1: $(test_oid t1_abbrev) = 1: $(test_oid u1_abbrev) s/5/A/
+ 2: $(test_oid t2_abbrev) = 2: $(test_oid u2_abbrev) s/4/A/
+ 3: $(test_oid t3_abbrev) = 3: $(test_oid u3_abbrev) s/11/B/
+ 4: $(test_oid t4_abbrev) = 4: $(test_oid u4_abbrev) s/12/B/
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'A^! and A^-<n> (unmodified)' '
+ git range-diff --no-color topic^! unmodified^-1 >actual &&
+ cat >expect <<-EOF &&
+ 1: $(test_oid t4) = 1: $(test_oid u4) s/12/B/
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'A^{/..} is not mistaken for a range' '
+ test_must_fail git range-diff topic^.. topic^{/..} -- 2>error &&
+ test_grep "not a commit range" error
'
test_expect_success 'trivial reordering' '
- git range-diff --no-color master topic reordered >actual &&
- cat >expected <<-EOF &&
+ git range-diff --no-color main topic reordered >actual &&
+ cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/
3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/
4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/
2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'removed a commit' '
- git range-diff --no-color master topic removed >actual &&
- cat >expected <<-EOF &&
+ git range-diff --no-color main topic removed >actual &&
+ cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/
2: $(test_oid t2) < -: $(test_oid __) s/4/A/
3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/
4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'added a commit' '
- git range-diff --no-color master topic added >actual &&
- cat >expected <<-EOF &&
+ git range-diff --no-color main topic added >actual &&
+ cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/
-: $(test_oid __) > 3: $(test_oid a3) s/6/A/
3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/
4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'new base, A B C' '
- git range-diff --no-color master topic rebased >actual &&
- cat >expected <<-EOF &&
+ git range-diff --no-color main topic rebased >actual &&
+ cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/
3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/
4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'new base, B...C' '
- # this syntax includes the commits from master!
+ # this syntax includes the commits from main!
git range-diff --no-color topic...rebased >actual &&
- cat >expected <<-EOF &&
+ cat >expect <<-EOF &&
-: $(test_oid __) > 1: $(test_oid b5) unrelated
1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/
2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/
3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/
4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'changed commit' '
git range-diff --no-color topic...changed >actual &&
- cat >expected <<-EOF &&
+ cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
@@ -226,42 +282,38 @@ test_expect_success 'changed commit' '
+B
13
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'changed commit with --no-patch diff option' '
git range-diff --no-color --no-patch topic...changed >actual &&
- cat >expected <<-EOF &&
+ cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'changed commit with --stat diff option' '
git range-diff --no-color --stat topic...changed >actual &&
- cat >expected <<-EOF &&
+ cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
- a => b | 0
- 1 file changed, 0 insertions(+), 0 deletions(-)
2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
- a => b | 0
- 1 file changed, 0 insertions(+), 0 deletions(-)
3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
- a => b | 0
- 1 file changed, 0 insertions(+), 0 deletions(-)
+ a => b | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/
- a => b | 0
- 1 file changed, 0 insertions(+), 0 deletions(-)
+ a => b | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'changed commit with sm config' '
git range-diff --no-color --submodule=log topic...changed >actual &&
- cat >expected <<-EOF &&
+ cat >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/
2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/
3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/
@@ -285,12 +337,12 @@ test_expect_success 'changed commit with sm config' '
+B
13
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'renamed file' '
git range-diff --no-color --submodule=log topic...renamed-file >actual &&
- sed s/Z/\ /g >expected <<-EOF &&
+ sed s/Z/\ /g >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/
2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/
@@ Metadata
@@ -330,13 +382,13 @@ test_expect_success 'renamed file' '
Z 10
Z B
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'file with mode only change' '
git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
- sed s/Z/\ /g >expected <<-EOF &&
- 1: fccce22 ! 1: 4d39cb3 s/4/A/
+ sed s/Z/\ /g >expect <<-EOF &&
+ 1: $(test_oid t2) ! 1: $(test_oid o1) s/4/A/
@@ Metadata
ZAuthor: Thomas Rast <trast@inf.ethz.ch>
Z
@@ -352,7 +404,7 @@ test_expect_success 'file with mode only change' '
Z 7
+
+ ## other-file (new) ##
- 2: 147e64e ! 2: 26c107f s/11/B/
+ 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/
@@ Metadata
ZAuthor: Thomas Rast <trast@inf.ethz.ch>
Z
@@ -368,14 +420,14 @@ test_expect_success 'file with mode only change' '
Z 14
+
+ ## other-file (mode change 100644 => 100755) ##
- 3: a63e992 = 3: 4c1e0f5 s/12/B/
+ 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'file added and later removed' '
git range-diff --no-color --submodule=log topic...added-removed >actual &&
- sed s/Z/\ /g >expected <<-EOF &&
+ sed s/Z/\ /g >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/
2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/
@@ Metadata
@@ -411,17 +463,17 @@ test_expect_success 'file added and later removed' '
+ ## new-file (deleted) ##
4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'no commits on one side' '
git commit --amend -m "new message" &&
- git range-diff master HEAD@{1} HEAD
+ git range-diff main HEAD@{1} HEAD
'
test_expect_success 'changed message' '
git range-diff --no-color topic...changed-message >actual &&
- sed s/Z/\ /g >expected <<-EOF &&
+ sed s/Z/\ /g >expect <<-EOF &&
1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/
2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/
@@ Metadata
@@ -436,7 +488,7 @@ test_expect_success 'changed message' '
3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/
4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/
EOF
- test_cmp expected actual
+ test_cmp expect actual
'
test_expect_success 'dual-coloring' '
@@ -478,14 +530,14 @@ test_expect_success 'dual-coloring' '
test_cmp expect actual
'
-for prev in topic master..topic
+for prev in topic main..topic
do
test_expect_success "format-patch --range-diff=$prev" '
git format-patch --cover-letter --range-diff=$prev \
- master..unmodified >actual &&
+ main..unmodified >actual &&
test_when_finished "rm 000?-*" &&
test_line_count = 5 actual &&
- test_i18ngrep "^Range-diff:$" 0000-* &&
+ test_grep "^Range-diff:$" 0000-* &&
grep "= 1: .* s/5/A" 0000-* &&
grep "= 2: .* s/4/A" 0000-* &&
grep "= 3: .* s/11/B" 0000-* &&
@@ -497,12 +549,349 @@ test_expect_success 'format-patch --range-diff as commentary' '
git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
test_when_finished "rm 0001-*" &&
test_line_count = 1 actual &&
- test_i18ngrep "^Range-diff:$" 0001-* &&
+ test_grep "^Range-diff:$" 0001-* &&
grep "> 1: .* new message" 0001-*
'
+test_expect_success 'format-patch --range-diff reroll-count with a non-integer' '
+ git format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&
+ test_when_finished "rm v2.9-0001-*" &&
+ test_line_count = 1 actual &&
+ test_grep "^Range-diff:$" v2.9-0001-* &&
+ grep "> 1: .* new message" v2.9-0001-*
+'
+
+test_expect_success 'format-patch --range-diff reroll-count with a integer' '
+ git format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&
+ test_when_finished "rm v2-0001-*" &&
+ test_line_count = 1 actual &&
+ test_grep "^Range-diff ..* v1:$" v2-0001-* &&
+ grep "> 1: .* new message" v2-0001-*
+'
+
+test_expect_success 'format-patch --range-diff with v0' '
+ git format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&
+ test_when_finished "rm v0-0001-*" &&
+ test_line_count = 1 actual &&
+ test_grep "^Range-diff:$" v0-0001-* &&
+ grep "> 1: .* new message" v0-0001-*
+'
+
test_expect_success 'range-diff overrides diff.noprefix internally' '
git -c diff.noprefix=true range-diff HEAD^...
'
+test_expect_success 'basic with modified format.pretty with suffix' '
+ git -c format.pretty="format:commit %H%d%n" range-diff \
+ main..topic main..unmodified
+'
+
+test_expect_success 'basic with modified format.pretty without "commit "' '
+ git -c format.pretty="format:%H%n" range-diff \
+ main..topic main..unmodified
+'
+
+test_expect_success 'range-diff compares notes by default' '
+ git notes add -m "topic note" topic &&
+ git notes add -m "unmodified note" unmodified &&
+ test_when_finished git notes remove topic unmodified &&
+ git range-diff --no-color main..topic main..unmodified \
+ >actual &&
+ sed s/Z/\ /g >expect <<-EOF &&
+ 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
+ 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
+ 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
+ 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
+ @@ Commit message
+ Z
+ Z
+ Z ## Notes ##
+ - topic note
+ + unmodified note
+ Z
+ Z ## file ##
+ Z@@ file: A
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'range-diff with --no-notes' '
+ git notes add -m "topic note" topic &&
+ git notes add -m "unmodified note" unmodified &&
+ test_when_finished git notes remove topic unmodified &&
+ git range-diff --no-color --no-notes main..topic main..unmodified \
+ >actual &&
+ cat >expect <<-EOF &&
+ 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
+ 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
+ 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
+ 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/
+ EOF
+ test_cmp expect actual
+'
+
+test_expect_success 'range-diff with multiple --notes' '
+ git notes --ref=note1 add -m "topic note1" topic &&
+ git notes --ref=note1 add -m "unmodified note1" unmodified &&
+ test_when_finished git notes --ref=note1 remove topic unmodified &&
+ git notes --ref=note2 add -m "topic note2" topic &&
+ git notes --ref=note2 add -m "unmodified note2" unmodified &&
+ test_when_finished git notes --ref=note2 remove topic unmodified &&
+ git range-diff --no-color --notes=note1 --notes=note2 main..topic main..unmodified \
+ >actual &&
+ sed s/Z/\ /g >expect <<-EOF &&
+ 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/
+ 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/
+ 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/
+ 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/
+ @@ Commit message
+ Z
+ Z
+ Z ## Notes (note1) ##
+ - topic note1
+ + unmodified note1
+ Z
+ Z
+ Z ## Notes (note2) ##
+ - topic note2
+ + unmodified note2
+ Z
+ Z ## file ##
+ Z@@ file: A
+ EOF
+ test_cmp expect actual
+'
+
+# `range-diff` should act like `log` with regards to notes
+test_expect_success 'range-diff with --notes=custom does not show default notes' '
+ git notes add -m "topic note" topic &&
+ git notes add -m "unmodified note" unmodified &&
+ git notes --ref=custom add -m "topic note" topic &&
+ git notes --ref=custom add -m "unmodified note" unmodified &&
+ test_when_finished git notes remove topic unmodified &&
+ test_when_finished git notes --ref=custom remove topic unmodified &&
+ git range-diff --notes=custom main..topic main..unmodified \
+ >actual &&
+ ! grep "## Notes ##" actual &&
+ grep "## Notes (custom) ##" actual
+'
+
+test_expect_success 'format-patch --range-diff does not compare notes by default' '
+ git notes add -m "topic note" topic &&
+ git notes add -m "unmodified note" unmodified &&
+ test_when_finished git notes remove topic unmodified &&
+ git format-patch --cover-letter --range-diff=$prev \
+ main..unmodified >actual &&
+ test_when_finished "rm 000?-*" &&
+ test_line_count = 5 actual &&
+ test_grep "^Range-diff:$" 0000-* &&
+ grep "= 1: .* s/5/A" 0000-* &&
+ grep "= 2: .* s/4/A" 0000-* &&
+ grep "= 3: .* s/11/B" 0000-* &&
+ grep "= 4: .* s/12/B" 0000-* &&
+ ! grep "Notes" 0000-* &&
+ ! grep "note" 0000-*
+'
+
+test_expect_success 'format-patch --notes=custom --range-diff only compares custom notes' '
+ git notes add -m "topic note" topic &&
+ git notes --ref=custom add -m "topic note (custom)" topic &&
+ git notes add -m "unmodified note" unmodified &&
+ git notes --ref=custom add -m "unmodified note (custom)" unmodified &&
+ test_when_finished git notes remove topic unmodified &&
+ test_when_finished git notes --ref=custom remove topic unmodified &&
+ git format-patch --notes=custom --cover-letter --range-diff=$prev \
+ main..unmodified >actual &&
+ test_when_finished "rm 000?-*" &&
+ grep "## Notes (custom) ##" 0000-* &&
+ ! grep "## Notes ##" 0000-*
+'
+
+test_expect_success 'format-patch --range-diff with --no-notes' '
+ git notes add -m "topic note" topic &&
+ git notes add -m "unmodified note" unmodified &&
+ test_when_finished git notes remove topic unmodified &&
+ git format-patch --no-notes --cover-letter --range-diff=$prev \
+ main..unmodified >actual &&
+ test_when_finished "rm 000?-*" &&
+ test_line_count = 5 actual &&
+ test_grep "^Range-diff:$" 0000-* &&
+ grep "= 1: .* s/5/A" 0000-* &&
+ grep "= 2: .* s/4/A" 0000-* &&
+ grep "= 3: .* s/11/B" 0000-* &&
+ grep "= 4: .* s/12/B" 0000-* &&
+ ! grep "Notes" 0000-* &&
+ ! grep "note" 0000-*
+'
+
+test_expect_success 'format-patch --range-diff with --notes' '
+ git notes add -m "topic note" topic &&
+ git notes add -m "unmodified note" unmodified &&
+ test_when_finished git notes remove topic unmodified &&
+ git format-patch --notes --cover-letter --range-diff=$prev \
+ main..unmodified >actual &&
+ test_when_finished "rm 000?-*" &&
+ test_line_count = 5 actual &&
+ test_grep "^Range-diff:$" 0000-* &&
+ grep "= 1: .* s/5/A" 0000-* &&
+ grep "= 2: .* s/4/A" 0000-* &&
+ grep "= 3: .* s/11/B" 0000-* &&
+ grep "! 4: .* s/12/B" 0000-* &&
+ sed s/Z/\ /g >expect <<-EOF &&
+ @@ Commit message
+ Z
+ Z
+ Z ## Notes ##
+ - topic note
+ + unmodified note
+ Z
+ Z ## file ##
+ Z@@ file: A
+ EOF
+ sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'format-patch --range-diff with format.notes config' '
+ git notes add -m "topic note" topic &&
+ git notes add -m "unmodified note" unmodified &&
+ test_when_finished git notes remove topic unmodified &&
+ test_config format.notes true &&
+ git format-patch --cover-letter --range-diff=$prev \
+ main..unmodified >actual &&
+ test_when_finished "rm 000?-*" &&
+ test_line_count = 5 actual &&
+ test_grep "^Range-diff:$" 0000-* &&
+ grep "= 1: .* s/5/A" 0000-* &&
+ grep "= 2: .* s/4/A" 0000-* &&
+ grep "= 3: .* s/11/B" 0000-* &&
+ grep "! 4: .* s/12/B" 0000-* &&
+ sed s/Z/\ /g >expect <<-EOF &&
+ @@ Commit message
+ Z
+ Z
+ Z ## Notes ##
+ - topic note
+ + unmodified note
+ Z
+ Z ## file ##
+ Z@@ file: A
+ EOF
+ sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'format-patch --range-diff with multiple notes' '
+ git notes --ref=note1 add -m "topic note1" topic &&
+ git notes --ref=note1 add -m "unmodified note1" unmodified &&
+ test_when_finished git notes --ref=note1 remove topic unmodified &&
+ git notes --ref=note2 add -m "topic note2" topic &&
+ git notes --ref=note2 add -m "unmodified note2" unmodified &&
+ test_when_finished git notes --ref=note2 remove topic unmodified &&
+ git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
+ main..unmodified >actual &&
+ test_when_finished "rm 000?-*" &&
+ test_line_count = 5 actual &&
+ test_grep "^Range-diff:$" 0000-* &&
+ grep "= 1: .* s/5/A" 0000-* &&
+ grep "= 2: .* s/4/A" 0000-* &&
+ grep "= 3: .* s/11/B" 0000-* &&
+ grep "! 4: .* s/12/B" 0000-* &&
+ sed s/Z/\ /g >expect <<-EOF &&
+ @@ Commit message
+ Z
+ Z
+ Z ## Notes (note1) ##
+ - topic note1
+ + unmodified note1
+ Z
+ Z
+ Z ## Notes (note2) ##
+ - topic note2
+ + unmodified note2
+ Z
+ Z ## file ##
+ Z@@ file: A
+ EOF
+ sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '--left-only/--right-only' '
+ git switch --orphan left-right &&
+ test_commit first &&
+ test_commit unmatched &&
+ test_commit common &&
+ git switch -C left-right first &&
+ git cherry-pick common &&
+
+ git range-diff -s --left-only ...common >actual &&
+ head_oid=$(git rev-parse --short HEAD) &&
+ common_oid=$(git rev-parse --short common) &&
+ echo "1: $head_oid = 2: $common_oid common" >expect &&
+ test_cmp expect actual
+'
+
+test_expect_success 'ranges with pathspecs' '
+ git range-diff topic...mode-only-change -- other-file >actual &&
+ test_line_count = 2 actual &&
+ topic_oid=$(git rev-parse --short topic) &&
+ mode_change_oid=$(git rev-parse --short mode-only-change^) &&
+ file_change_oid=$(git rev-parse --short mode-only-change) &&
+ grep "$mode_change_oid" actual &&
+ ! grep "$file_change_oid" actual &&
+ ! grep "$topic_oid" actual
+'
+
+test_expect_success 'submodule changes are shown irrespective of diff.submodule' '
+ git init sub-repo &&
+ test_commit -C sub-repo sub-first &&
+ sub_oid1=$(git -C sub-repo rev-parse HEAD) &&
+ test_commit -C sub-repo sub-second &&
+ sub_oid2=$(git -C sub-repo rev-parse HEAD) &&
+ test_commit -C sub-repo sub-third &&
+ sub_oid3=$(git -C sub-repo rev-parse HEAD) &&
+
+ git checkout -b main-sub topic &&
+ git -c protocol.file.allow=always submodule add ./sub-repo sub &&
+ git -C sub checkout --detach sub-first &&
+ git commit -m "add sub" sub &&
+ sup_oid1=$(git rev-parse --short HEAD) &&
+ git checkout -b topic-sub &&
+ git -C sub checkout sub-second &&
+ git commit -m "change sub" sub &&
+ sup_oid2=$(git rev-parse --short HEAD) &&
+ git checkout -b modified-sub main-sub &&
+ git -C sub checkout sub-third &&
+ git commit -m "change sub" sub &&
+ sup_oid3=$(git rev-parse --short HEAD) &&
+ sup_oid0=$(test_oid __) &&
+
+ test_config diff.submodule log &&
+ git range-diff topic topic-sub modified-sub >actual &&
+ cat >expect <<-EOF &&
+ 1: $sup_oid1 = 1: $sup_oid1 add sub
+ 2: $sup_oid2 < -: $sup_oid0 change sub
+ -: $sup_oid0 > 2: $sup_oid3 change sub
+ EOF
+ test_cmp expect actual &&
+ test_config diff.submodule diff &&
+ git range-diff topic topic-sub modified-sub >actual &&
+ git range-diff --creation-factor=100 topic topic-sub modified-sub >actual &&
+ cat >expect <<-EOF &&
+ 1: $sup_oid1 = 1: $sup_oid1 add sub
+ 2: $sup_oid2 ! 2: $sup_oid3 change sub
+ @@ Commit message
+ ## sub ##
+ @@
+ -Subproject commit $sub_oid1
+ -+Subproject commit $sub_oid2
+ ++Subproject commit $sub_oid3
+ EOF
+ test_cmp expect actual &&
+ test_config diff.submodule diff &&
+ git range-diff --creation-factor=100 topic topic-sub modified-sub >actual &&
+ test_cmp expect actual
+'
+
test_done