]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t3206-range-diff.sh
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
14 test_expect_success
'simple A..B A..C (unmodified)' '
15 git range-diff --no-color master..topic master..unmodified \
17 cat >expected <<-EOF &&
18 1: 4de457d = 1: 35b9b25 s/5/A/
19 2: fccce22 = 2: de345ab s/4/A/
20 3: 147e64e = 3: 9af6654 s/11/B/
21 4: a63e992 = 4: 2901f77 s/12/B/
23 test_cmp expected actual
26 test_expect_success
'simple B...C (unmodified)' '
27 git range-diff --no-color topic...unmodified >actual &&
28 # same "expected" as above
29 test_cmp expected actual
32 test_expect_success
'simple A B C (unmodified)' '
33 git range-diff --no-color master topic unmodified >actual &&
34 # same "expected" as above
35 test_cmp expected actual
38 test_expect_success
'trivial reordering' '
39 git range-diff --no-color master topic reordered >actual &&
40 cat >expected <<-EOF &&
41 1: 4de457d = 1: aca177a s/5/A/
42 3: 147e64e = 2: 14ad629 s/11/B/
43 4: a63e992 = 3: ee58208 s/12/B/
44 2: fccce22 = 4: 307b27a s/4/A/
46 test_cmp expected actual
49 test_expect_success
'removed a commit' '
50 git range-diff --no-color master topic removed >actual &&
51 cat >expected <<-EOF &&
52 1: 4de457d = 1: 7657159 s/5/A/
53 2: fccce22 < -: ------- s/4/A/
54 3: 147e64e = 2: 43d84d3 s/11/B/
55 4: a63e992 = 3: a740396 s/12/B/
57 test_cmp expected actual
60 test_expect_success
'added a commit' '
61 git range-diff --no-color master topic added >actual &&
62 cat >expected <<-EOF &&
63 1: 4de457d = 1: 2716022 s/5/A/
64 2: fccce22 = 2: b62accd s/4/A/
65 -: ------- > 3: df46cfa s/6/A/
66 3: 147e64e = 4: 3e64548 s/11/B/
67 4: a63e992 = 5: 12b4063 s/12/B/
69 test_cmp expected actual
72 test_expect_success
'new base, A B C' '
73 git range-diff --no-color master topic rebased >actual &&
74 cat >expected <<-EOF &&
75 1: 4de457d = 1: cc9c443 s/5/A/
76 2: fccce22 = 2: c5d9641 s/4/A/
77 3: 147e64e = 3: 28cc2b6 s/11/B/
78 4: a63e992 = 4: 5628ab7 s/12/B/
80 test_cmp expected actual
83 test_expect_success
'new base, B...C' '
84 # this syntax includes the commits from master!
85 git range-diff --no-color topic...rebased >actual &&
86 cat >expected <<-EOF &&
87 -: ------- > 1: a31b12e unrelated
88 1: 4de457d = 2: cc9c443 s/5/A/
89 2: fccce22 = 3: c5d9641 s/4/A/
90 3: 147e64e = 4: 28cc2b6 s/11/B/
91 4: a63e992 = 5: 5628ab7 s/12/B/
93 test_cmp expected actual
96 test_expect_success
'changed commit' '
97 git range-diff --no-color topic...changed >actual &&
98 cat >expected <<-EOF &&
99 1: 4de457d = 1: a4b3333 s/5/A/
100 2: fccce22 = 2: f51d370 s/4/A/
101 3: 147e64e ! 3: 0559556 s/11/B/
111 4: a63e992 ! 4: d966c5c s/12/B/
122 test_cmp expected actual
125 test_expect_success
'changed commit with --no-patch diff option' '
126 git range-diff --no-color --no-patch topic...changed >actual &&
127 cat >expected <<-EOF &&
128 1: 4de457d = 1: a4b3333 s/5/A/
129 2: fccce22 = 2: f51d370 s/4/A/
130 3: 147e64e ! 3: 0559556 s/11/B/
131 4: a63e992 ! 4: d966c5c s/12/B/
133 test_cmp expected actual
136 test_expect_success
'changed commit with --stat diff option' '
137 git range-diff --no-color --stat topic...changed >actual &&
138 cat >expected <<-EOF &&
139 1: 4de457d = 1: a4b3333 s/5/A/
141 1 file changed, 0 insertions(+), 0 deletions(-)
142 2: fccce22 = 2: f51d370 s/4/A/
144 1 file changed, 0 insertions(+), 0 deletions(-)
145 3: 147e64e ! 3: 0559556 s/11/B/
147 1 file changed, 0 insertions(+), 0 deletions(-)
148 4: a63e992 ! 4: d966c5c s/12/B/
150 1 file changed, 0 insertions(+), 0 deletions(-)
152 test_cmp expected actual
155 test_expect_success
'changed commit with sm config' '
156 git range-diff --no-color --submodule=log topic...changed >actual &&
157 cat >expected <<-EOF &&
158 1: 4de457d = 1: a4b3333 s/5/A/
159 2: fccce22 = 2: f51d370 s/4/A/
160 3: 147e64e ! 3: 0559556 s/11/B/
170 4: a63e992 ! 4: d966c5c s/12/B/
181 test_cmp expected actual
184 test_expect_success
'renamed file' '
185 git range-diff --no-color --submodule=log topic...renamed-file >actual &&
186 sed s/Z/\ /g >expected <<-EOF &&
187 1: 4de457d = 1: f258d75 s/5/A/
188 2: fccce22 ! 2: 017b62d s/4/A/
190 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
192 Z ## Commit message ##
194 + s/4/A/ + rename file
197 + ## file => renamed-file ##
201 3: 147e64e ! 3: 3ce7af6 s/11/B/
203 Z ## Commit message ##
213 4: a63e992 ! 4: 1e6226b s/12/B/
215 Z ## Commit message ##
226 test_cmp expected actual
229 test_expect_success
'file with mode only change' '
230 git range-diff --no-color --submodule=log topic...mode-only-change >actual &&
231 sed s/Z/\ /g >expected <<-EOF &&
232 1: fccce22 ! 1: 4d39cb3 s/4/A/
234 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
236 Z ## Commit message ##
238 + s/4/A/ + add other-file
247 + ## other-file (new) ##
248 2: 147e64e ! 2: 26c107f s/11/B/
250 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
252 Z ## Commit message ##
254 + s/11/B/ + mode change other-file
263 + ## other-file (mode change 100644 => 100755) ##
264 3: a63e992 = 3: 4c1e0f5 s/12/B/
266 test_cmp expected actual
269 test_expect_success
'file added and later removed' '
270 git range-diff --no-color --submodule=log topic...added-removed >actual &&
271 sed s/Z/\ /g >expected <<-EOF &&
272 1: 4de457d = 1: 096b1ba s/5/A/
273 2: fccce22 ! 2: d92e698 s/4/A/
275 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
277 Z ## Commit message ##
288 + ## new-file (new) ##
289 3: 147e64e ! 3: 9a1db4d s/11/B/
291 ZAuthor: Thomas Rast <trast@inf.ethz.ch>
293 Z ## Commit message ##
295 + s/11/B/ + remove file
304 + ## new-file (deleted) ##
305 4: a63e992 = 4: fea3b5c s/12/B/
307 test_cmp expected actual
310 test_expect_success
'no commits on one side' '
311 git commit --amend -m "new message" &&
312 git range-diff master HEAD@{1} HEAD
315 test_expect_success
'changed message' '
316 git range-diff --no-color topic...changed-message >actual &&
317 sed s/Z/\ /g >expected <<-EOF &&
318 1: 4de457d = 1: f686024 s/5/A/
319 2: fccce22 ! 2: 4ab067d s/4/A/
321 Z ## Commit message ##
324 + Also a silly comment here!
329 3: 147e64e = 3: b9cb956 s/11/B/
330 4: a63e992 = 4: 8add5f1 s/12/B/
332 test_cmp expected actual
335 test_expect_success
'dual-coloring' '
336 sed -e "s|^:||" >expect <<-\EOF &&
337 :<YELLOW>1: a4b3333 = 1: f686024 s/5/A/<RESET>
338 :<RED>2: f51d370 <RESET><YELLOW>!<RESET><GREEN> 2: 4ab067d<RESET><YELLOW> s/4/A/<RESET>
339 : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET>
340 : ## Commit message ##<RESET>
343 : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET>
344 : <REVERSE><GREEN>+<RESET>
348 :<RED>3: 0559556 <RESET><YELLOW>!<RESET><GREEN> 3: b9cb956<RESET><YELLOW> s/11/B/<RESET>
349 : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET>
353 : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET>
354 : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET>
358 :<RED>4: d966c5c <RESET><YELLOW>!<RESET><GREEN> 4: 8add5f1<RESET><YELLOW> s/12/B/<RESET>
359 : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET>
360 : <CYAN> @@ file: A<RESET>
363 : <REVERSE><RED>-<RESET><FAINT> BB<RESET>
364 : <REVERSE><GREEN>+<RESET><BOLD> B<RESET>
369 git range-diff changed...changed-message --color --dual-color >actual.raw &&
370 test_decode_color >actual <actual.raw &&
371 test_cmp expect actual
374 for prev
in topic master..topic
376 test_expect_success
"format-patch --range-diff=$prev" '
377 git format-patch --cover-letter --range-diff=$prev \
378 master..unmodified >actual &&
379 test_when_finished "rm 000?-*" &&
380 test_line_count = 5 actual &&
381 test_i18ngrep "^Range-diff:$" 0000-* &&
382 grep "= 1: .* s/5/A" 0000-* &&
383 grep "= 2: .* s/4/A" 0000-* &&
384 grep "= 3: .* s/11/B" 0000-* &&
385 grep "= 4: .* s/12/B" 0000-*
389 test_expect_success
'format-patch --range-diff as commentary' '
390 git format-patch --range-diff=HEAD~1 HEAD~1 >actual &&
391 test_when_finished "rm 0001-*" &&
392 test_line_count = 1 actual &&
393 test_i18ngrep "^Range-diff:$" 0001-* &&
394 grep "> 1: .* new message" 0001-*