]>
Commit | Line | Data |
---|---|---|
8884cf15 TR |
1 | #!/bin/sh |
2 | ||
3 | test_description='range-diff tests' | |
4 | ||
d6c6b108 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
8884cf15 TR |
8 | . ./test-lib.sh |
9 | ||
10 | # Note that because of the range-diff's heuristics, test_commit does more | |
11 | # harm than good. We need some real history. | |
12 | ||
13 | test_expect_success 'setup' ' | |
3a6e48e9 | 14 | git fast-import <"$TEST_DIRECTORY"/t3206/history.export && |
79f3950d | 15 | test_oid_cache <<-\EOF |
b561edd2 | 16 | # topic |
17 | t1 sha1:4de457d | |
18 | t2 sha1:fccce22 | |
19 | t3 sha1:147e64e | |
20 | t4 sha1:a63e992 | |
21 | t1 sha256:b89f8b9 | |
22 | t2 sha256:5f12aad | |
23 | t3 sha256:ea8b273 | |
24 | t4 sha256:14b7336 | |
25 | ||
26 | # unmodified | |
27 | u1 sha1:35b9b25 | |
28 | u2 sha1:de345ab | |
29 | u3 sha1:9af6654 | |
30 | u4 sha1:2901f77 | |
31 | u1 sha256:e3731be | |
32 | u2 sha256:14fadf8 | |
33 | u3 sha256:736c4bc | |
34 | u4 sha256:673e77d | |
35 | ||
36 | # reordered | |
37 | r1 sha1:aca177a | |
38 | r2 sha1:14ad629 | |
39 | r3 sha1:ee58208 | |
40 | r4 sha1:307b27a | |
41 | r1 sha256:f59d3aa | |
42 | r2 sha256:fb261a8 | |
43 | r3 sha256:cb2649b | |
44 | r4 sha256:958577e | |
45 | ||
46 | # removed (deleted) | |
47 | d1 sha1:7657159 | |
48 | d2 sha1:43d84d3 | |
49 | d3 sha1:a740396 | |
50 | d1 sha256:e312513 | |
51 | d2 sha256:eb19258 | |
52 | d3 sha256:1ccb3c1 | |
53 | ||
54 | # added | |
55 | a1 sha1:2716022 | |
56 | a2 sha1:b62accd | |
57 | a3 sha1:df46cfa | |
58 | a4 sha1:3e64548 | |
59 | a5 sha1:12b4063 | |
60 | a1 sha256:d724f4d | |
61 | a2 sha256:1de7762 | |
62 | a3 sha256:e159431 | |
63 | a4 sha256:b3e483c | |
64 | a5 sha256:90866a7 | |
65 | ||
66 | # rebased | |
67 | b1 sha1:cc9c443 | |
68 | b2 sha1:c5d9641 | |
69 | b3 sha1:28cc2b6 | |
70 | b4 sha1:5628ab7 | |
71 | b5 sha1:a31b12e | |
72 | b1 sha256:a1a8717 | |
73 | b2 sha256:20a5862 | |
74 | b3 sha256:587172a | |
75 | b4 sha256:2721c5d | |
76 | b5 sha256:7b57864 | |
77 | ||
78 | # changed | |
79 | c1 sha1:a4b3333 | |
80 | c2 sha1:f51d370 | |
81 | c3 sha1:0559556 | |
82 | c4 sha1:d966c5c | |
83 | c1 sha256:f8c2b9d | |
84 | c2 sha256:3fb6318 | |
85 | c3 sha256:168ab68 | |
86 | c4 sha256:3526539 | |
87 | ||
88 | # changed-message | |
89 | m1 sha1:f686024 | |
90 | m2 sha1:4ab067d | |
91 | m3 sha1:b9cb956 | |
92 | m4 sha1:8add5f1 | |
93 | m1 sha256:31e6281 | |
94 | m2 sha256:a06bf1b | |
95 | m3 sha256:82dc654 | |
96 | m4 sha256:48470c5 | |
97 | ||
98 | # renamed | |
99 | n1 sha1:f258d75 | |
100 | n2 sha1:017b62d | |
101 | n3 sha1:3ce7af6 | |
102 | n4 sha1:1e6226b | |
103 | n1 sha256:ad52114 | |
104 | n2 sha256:3b54c8f | |
105 | n3 sha256:3b0a644 | |
106 | n4 sha256:e461653 | |
107 | ||
94db7e3e | 108 | # mode change |
109 | o1 sha1:4d39cb3 | |
110 | o2 sha1:26c107f | |
111 | o3 sha1:4c1e0f5 | |
112 | o1 sha256:d0dd598 | |
113 | o2 sha256:c4a279e | |
114 | o3 sha256:78459d7 | |
115 | ||
b561edd2 | 116 | # added and removed |
117 | s1 sha1:096b1ba | |
118 | s2 sha1:d92e698 | |
119 | s3 sha1:9a1db4d | |
120 | s4 sha1:fea3b5c | |
121 | s1 sha256:a7f9134 | |
122 | s2 sha256:b4c2580 | |
123 | s3 sha256:1d62aa2 | |
124 | s4 sha256:48160e8 | |
125 | ||
126 | # Empty delimiter (included so lines match neatly) | |
127 | __ sha1:------- | |
128 | __ sha256:------- | |
129 | EOF | |
8884cf15 TR |
130 | ' |
131 | ||
132 | test_expect_success 'simple A..B A..C (unmodified)' ' | |
d6c6b108 | 133 | git range-diff --no-color main..topic main..unmodified \ |
8884cf15 | 134 | >actual && |
75c5aa07 | 135 | cat >expect <<-EOF && |
b561edd2 | 136 | 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/ |
137 | 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/ | |
138 | 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/ | |
139 | 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/ | |
8884cf15 | 140 | EOF |
75c5aa07 | 141 | test_cmp expect actual |
8884cf15 TR |
142 | ' |
143 | ||
144 | test_expect_success 'simple B...C (unmodified)' ' | |
145 | git range-diff --no-color topic...unmodified >actual && | |
75c5aa07 DL |
146 | # same "expect" as above |
147 | test_cmp expect actual | |
8884cf15 TR |
148 | ' |
149 | ||
150 | test_expect_success 'simple A B C (unmodified)' ' | |
d6c6b108 | 151 | git range-diff --no-color main topic unmodified >actual && |
75c5aa07 DL |
152 | # same "expect" as above |
153 | test_cmp expect actual | |
8884cf15 TR |
154 | ' |
155 | ||
359f0d75 JS |
156 | test_expect_success 'A^! and A^-<n> (unmodified)' ' |
157 | git range-diff --no-color topic^! unmodified^-1 >actual && | |
158 | cat >expect <<-EOF && | |
159 | 1: $(test_oid t4) = 1: $(test_oid u4) s/12/B/ | |
160 | EOF | |
161 | test_cmp expect actual | |
162 | ' | |
163 | ||
164 | test_expect_success 'A^{/..} is not mistaken for a range' ' | |
165 | test_must_fail git range-diff topic^.. topic^{/..} 2>error && | |
166 | test_i18ngrep "not a commit range" error | |
167 | ' | |
168 | ||
8884cf15 | 169 | test_expect_success 'trivial reordering' ' |
d6c6b108 | 170 | git range-diff --no-color main topic reordered >actual && |
75c5aa07 | 171 | cat >expect <<-EOF && |
b561edd2 | 172 | 1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/ |
173 | 3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/ | |
174 | 4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/ | |
175 | 2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/ | |
8884cf15 | 176 | EOF |
75c5aa07 | 177 | test_cmp expect actual |
8884cf15 TR |
178 | ' |
179 | ||
180 | test_expect_success 'removed a commit' ' | |
d6c6b108 | 181 | git range-diff --no-color main topic removed >actual && |
75c5aa07 | 182 | cat >expect <<-EOF && |
b561edd2 | 183 | 1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/ |
184 | 2: $(test_oid t2) < -: $(test_oid __) s/4/A/ | |
185 | 3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/ | |
186 | 4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/ | |
8884cf15 | 187 | EOF |
75c5aa07 | 188 | test_cmp expect actual |
8884cf15 TR |
189 | ' |
190 | ||
191 | test_expect_success 'added a commit' ' | |
d6c6b108 | 192 | git range-diff --no-color main topic added >actual && |
75c5aa07 | 193 | cat >expect <<-EOF && |
b561edd2 | 194 | 1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/ |
195 | 2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/ | |
196 | -: $(test_oid __) > 3: $(test_oid a3) s/6/A/ | |
197 | 3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/ | |
198 | 4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/ | |
8884cf15 | 199 | EOF |
75c5aa07 | 200 | test_cmp expect actual |
8884cf15 TR |
201 | ' |
202 | ||
203 | test_expect_success 'new base, A B C' ' | |
d6c6b108 | 204 | git range-diff --no-color main topic rebased >actual && |
75c5aa07 | 205 | cat >expect <<-EOF && |
b561edd2 | 206 | 1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/ |
207 | 2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/ | |
208 | 3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/ | |
209 | 4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/ | |
8884cf15 | 210 | EOF |
75c5aa07 | 211 | test_cmp expect actual |
8884cf15 TR |
212 | ' |
213 | ||
214 | test_expect_success 'new base, B...C' ' | |
d6c6b108 | 215 | # this syntax includes the commits from main! |
8884cf15 | 216 | git range-diff --no-color topic...rebased >actual && |
75c5aa07 | 217 | cat >expect <<-EOF && |
b561edd2 | 218 | -: $(test_oid __) > 1: $(test_oid b5) unrelated |
219 | 1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/ | |
220 | 2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/ | |
221 | 3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/ | |
222 | 4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/ | |
8884cf15 | 223 | EOF |
75c5aa07 | 224 | test_cmp expect actual |
8884cf15 TR |
225 | ' |
226 | ||
227 | test_expect_success 'changed commit' ' | |
228 | git range-diff --no-color topic...changed >actual && | |
75c5aa07 | 229 | cat >expect <<-EOF && |
b561edd2 | 230 | 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ |
231 | 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ | |
232 | 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ | |
499352c2 | 233 | @@ file: A |
8884cf15 TR |
234 | 9 |
235 | 10 | |
236 | -11 | |
237 | -+B | |
238 | ++BB | |
239 | 12 | |
240 | 13 | |
241 | 14 | |
b561edd2 | 242 | 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ |
499352c2 | 243 | @@ file |
444e0969 | 244 | @@ file: A |
8884cf15 TR |
245 | 9 |
246 | 10 | |
247 | - B | |
248 | + BB | |
249 | -12 | |
250 | +B | |
251 | 13 | |
252 | EOF | |
75c5aa07 | 253 | test_cmp expect actual |
8884cf15 TR |
254 | ' |
255 | ||
4624185a ÆAB |
256 | test_expect_success 'changed commit with --no-patch diff option' ' |
257 | git range-diff --no-color --no-patch topic...changed >actual && | |
75c5aa07 | 258 | cat >expect <<-EOF && |
b561edd2 | 259 | 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ |
260 | 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ | |
261 | 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ | |
262 | 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ | |
4624185a | 263 | EOF |
75c5aa07 | 264 | test_cmp expect actual |
4624185a ÆAB |
265 | ' |
266 | ||
267 | test_expect_success 'changed commit with --stat diff option' ' | |
4624185a | 268 | git range-diff --no-color --stat topic...changed >actual && |
75c5aa07 | 269 | cat >expect <<-EOF && |
b561edd2 | 270 | 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ |
b561edd2 | 271 | 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ |
b561edd2 | 272 | 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ |
ff0c7fa8 TGS |
273 | a => b | 2 +- |
274 | 1 file changed, 1 insertion(+), 1 deletion(-) | |
b561edd2 | 275 | 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ |
ff0c7fa8 TGS |
276 | a => b | 2 +- |
277 | 1 file changed, 1 insertion(+), 1 deletion(-) | |
4624185a | 278 | EOF |
75c5aa07 | 279 | test_cmp expect actual |
4624185a ÆAB |
280 | ' |
281 | ||
0e573e8f LDM |
282 | test_expect_success 'changed commit with sm config' ' |
283 | git range-diff --no-color --submodule=log topic...changed >actual && | |
75c5aa07 | 284 | cat >expect <<-EOF && |
b561edd2 | 285 | 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ |
286 | 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ | |
287 | 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ | |
499352c2 | 288 | @@ file: A |
0e573e8f LDM |
289 | 9 |
290 | 10 | |
291 | -11 | |
292 | -+B | |
293 | ++BB | |
294 | 12 | |
295 | 13 | |
296 | 14 | |
b561edd2 | 297 | 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ |
499352c2 | 298 | @@ file |
444e0969 | 299 | @@ file: A |
0e573e8f LDM |
300 | 9 |
301 | 10 | |
302 | - B | |
303 | + BB | |
304 | -12 | |
305 | +B | |
306 | 13 | |
307 | EOF | |
75c5aa07 | 308 | test_cmp expect actual |
0e573e8f LDM |
309 | ' |
310 | ||
b66885a3 TG |
311 | test_expect_success 'renamed file' ' |
312 | git range-diff --no-color --submodule=log topic...renamed-file >actual && | |
75c5aa07 | 313 | sed s/Z/\ /g >expect <<-EOF && |
b561edd2 | 314 | 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/ |
315 | 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/ | |
499352c2 | 316 | @@ Metadata |
b66885a3 TG |
317 | ZAuthor: Thomas Rast <trast@inf.ethz.ch> |
318 | Z | |
499352c2 | 319 | Z ## Commit message ## |
b66885a3 TG |
320 | - s/4/A/ |
321 | + s/4/A/ + rename file | |
322 | Z | |
323 | - ## file ## | |
324 | + ## file => renamed-file ## | |
325 | Z@@ | |
326 | Z 1 | |
327 | Z 2 | |
b561edd2 | 328 | 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/ |
499352c2 TG |
329 | @@ Metadata |
330 | Z ## Commit message ## | |
b66885a3 TG |
331 | Z s/11/B/ |
332 | Z | |
333 | - ## file ## | |
444e0969 | 334 | -@@ file: A |
b66885a3 | 335 | + ## renamed-file ## |
444e0969 | 336 | +@@ renamed-file: A |
b66885a3 TG |
337 | Z 8 |
338 | Z 9 | |
444e0969 | 339 | Z 10 |
b561edd2 | 340 | 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/ |
499352c2 TG |
341 | @@ Metadata |
342 | Z ## Commit message ## | |
b66885a3 TG |
343 | Z s/12/B/ |
344 | Z | |
345 | - ## file ## | |
444e0969 | 346 | -@@ file: A |
b66885a3 | 347 | + ## renamed-file ## |
444e0969 | 348 | +@@ renamed-file: A |
b66885a3 TG |
349 | Z 9 |
350 | Z 10 | |
444e0969 | 351 | Z B |
b66885a3 | 352 | EOF |
75c5aa07 | 353 | test_cmp expect actual |
b66885a3 TG |
354 | ' |
355 | ||
2b6a9b13 TG |
356 | test_expect_success 'file with mode only change' ' |
357 | git range-diff --no-color --submodule=log topic...mode-only-change >actual && | |
75c5aa07 | 358 | sed s/Z/\ /g >expect <<-EOF && |
94db7e3e | 359 | 1: $(test_oid t2) ! 1: $(test_oid o1) s/4/A/ |
2b6a9b13 TG |
360 | @@ Metadata |
361 | ZAuthor: Thomas Rast <trast@inf.ethz.ch> | |
362 | Z | |
363 | Z ## Commit message ## | |
364 | - s/4/A/ | |
365 | + s/4/A/ + add other-file | |
366 | Z | |
367 | Z ## file ## | |
368 | Z@@ | |
369 | @@ file | |
370 | Z A | |
371 | Z 6 | |
372 | Z 7 | |
373 | + | |
374 | + ## other-file (new) ## | |
94db7e3e | 375 | 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/ |
2b6a9b13 TG |
376 | @@ Metadata |
377 | ZAuthor: Thomas Rast <trast@inf.ethz.ch> | |
378 | Z | |
379 | Z ## Commit message ## | |
380 | - s/11/B/ | |
381 | + s/11/B/ + mode change other-file | |
382 | Z | |
383 | Z ## file ## | |
384 | Z@@ file: A | |
385 | @@ file: A | |
386 | Z 12 | |
387 | Z 13 | |
388 | Z 14 | |
389 | + | |
390 | + ## other-file (mode change 100644 => 100755) ## | |
94db7e3e | 391 | 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/ |
2b6a9b13 | 392 | EOF |
75c5aa07 | 393 | test_cmp expect actual |
2b6a9b13 TG |
394 | ' |
395 | ||
b66885a3 TG |
396 | test_expect_success 'file added and later removed' ' |
397 | git range-diff --no-color --submodule=log topic...added-removed >actual && | |
75c5aa07 | 398 | sed s/Z/\ /g >expect <<-EOF && |
b561edd2 | 399 | 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/ |
400 | 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/ | |
499352c2 | 401 | @@ Metadata |
b66885a3 TG |
402 | ZAuthor: Thomas Rast <trast@inf.ethz.ch> |
403 | Z | |
499352c2 | 404 | Z ## Commit message ## |
b66885a3 TG |
405 | - s/4/A/ |
406 | + s/4/A/ + new-file | |
407 | Z | |
408 | Z ## file ## | |
409 | Z@@ | |
499352c2 | 410 | @@ file |
b66885a3 TG |
411 | Z A |
412 | Z 6 | |
413 | Z 7 | |
414 | + | |
415 | + ## new-file (new) ## | |
b561edd2 | 416 | 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/ |
499352c2 | 417 | @@ Metadata |
b66885a3 TG |
418 | ZAuthor: Thomas Rast <trast@inf.ethz.ch> |
419 | Z | |
499352c2 | 420 | Z ## Commit message ## |
b66885a3 TG |
421 | - s/11/B/ |
422 | + s/11/B/ + remove file | |
423 | Z | |
424 | Z ## file ## | |
444e0969 | 425 | Z@@ file: A |
499352c2 | 426 | @@ file: A |
b66885a3 TG |
427 | Z 12 |
428 | Z 13 | |
429 | Z 14 | |
430 | + | |
431 | + ## new-file (deleted) ## | |
b561edd2 | 432 | 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/ |
b66885a3 | 433 | EOF |
75c5aa07 | 434 | test_cmp expect actual |
b66885a3 TG |
435 | ' |
436 | ||
51bbcda1 JH |
437 | test_expect_success 'no commits on one side' ' |
438 | git commit --amend -m "new message" && | |
d6c6b108 | 439 | git range-diff main HEAD@{1} HEAD |
51bbcda1 JH |
440 | ' |
441 | ||
8884cf15 TR |
442 | test_expect_success 'changed message' ' |
443 | git range-diff --no-color topic...changed-message >actual && | |
75c5aa07 | 444 | sed s/Z/\ /g >expect <<-EOF && |
b561edd2 | 445 | 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/ |
446 | 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/ | |
499352c2 TG |
447 | @@ Metadata |
448 | Z ## Commit message ## | |
8884cf15 TR |
449 | Z s/4/A/ |
450 | Z | |
451 | + Also a silly comment here! | |
452 | + | |
b66885a3 TG |
453 | Z ## file ## |
454 | Z@@ | |
455 | Z 1 | |
b561edd2 | 456 | 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/ |
457 | 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/ | |
8884cf15 | 458 | EOF |
75c5aa07 | 459 | test_cmp expect actual |
8884cf15 TR |
460 | ' |
461 | ||
c5e64caa | 462 | test_expect_success 'dual-coloring' ' |
b561edd2 | 463 | sed -e "s|^:||" >expect <<-EOF && |
464 | :<YELLOW>1: $(test_oid c1) = 1: $(test_oid m1) s/5/A/<RESET> | |
465 | :<RED>2: $(test_oid c2) <RESET><YELLOW>!<RESET><GREEN> 2: $(test_oid m2)<RESET><YELLOW> s/4/A/<RESET> | |
499352c2 TG |
466 | : <REVERSE><CYAN>@@<RESET> <RESET>Metadata<RESET> |
467 | : ## Commit message ##<RESET> | |
c5e64caa SB |
468 | : s/4/A/<RESET> |
469 | : <RESET> | |
470 | : <REVERSE><GREEN>+<RESET><BOLD> Also a silly comment here!<RESET> | |
29ef759d | 471 | : <REVERSE><GREEN>+<RESET> |
b66885a3 TG |
472 | : ## file ##<RESET> |
473 | : <CYAN> @@<RESET> | |
474 | : 1<RESET> | |
b561edd2 | 475 | :<RED>3: $(test_oid c3) <RESET><YELLOW>!<RESET><GREEN> 3: $(test_oid m3)<RESET><YELLOW> s/11/B/<RESET> |
499352c2 | 476 | : <REVERSE><CYAN>@@<RESET> <RESET>file: A<RESET> |
c5e64caa SB |
477 | : 9<RESET> |
478 | : 10<RESET> | |
479 | : <RED> -11<RESET> | |
480 | : <REVERSE><RED>-<RESET><FAINT;GREEN>+BB<RESET> | |
481 | : <REVERSE><GREEN>+<RESET><BOLD;GREEN>+B<RESET> | |
482 | : 12<RESET> | |
483 | : 13<RESET> | |
484 | : 14<RESET> | |
b561edd2 | 485 | :<RED>4: $(test_oid c4) <RESET><YELLOW>!<RESET><GREEN> 4: $(test_oid m4)<RESET><YELLOW> s/12/B/<RESET> |
499352c2 | 486 | : <REVERSE><CYAN>@@<RESET> <RESET>file<RESET> |
444e0969 | 487 | : <CYAN> @@ file: A<RESET> |
c5e64caa SB |
488 | : 9<RESET> |
489 | : 10<RESET> | |
490 | : <REVERSE><RED>-<RESET><FAINT> BB<RESET> | |
491 | : <REVERSE><GREEN>+<RESET><BOLD> B<RESET> | |
492 | : <RED> -12<RESET> | |
493 | : <GREEN> +B<RESET> | |
494 | : 13<RESET> | |
495 | EOF | |
496 | git range-diff changed...changed-message --color --dual-color >actual.raw && | |
497 | test_decode_color >actual <actual.raw && | |
498 | test_cmp expect actual | |
499 | ' | |
500 | ||
d6c6b108 | 501 | for prev in topic main..topic |
31e2617a ES |
502 | do |
503 | test_expect_success "format-patch --range-diff=$prev" ' | |
ac0edf1f | 504 | git format-patch --cover-letter --range-diff=$prev \ |
d6c6b108 | 505 | main..unmodified >actual && |
ac0edf1f MÃ… |
506 | test_when_finished "rm 000?-*" && |
507 | test_line_count = 5 actual && | |
508 | test_i18ngrep "^Range-diff:$" 0000-* && | |
509 | grep "= 1: .* s/5/A" 0000-* && | |
510 | grep "= 2: .* s/4/A" 0000-* && | |
511 | grep "= 3: .* s/11/B" 0000-* && | |
512 | grep "= 4: .* s/12/B" 0000-* | |
31e2617a ES |
513 | ' |
514 | done | |
515 | ||
cdc067c3 | 516 | test_expect_success 'format-patch --range-diff as commentary' ' |
ac0edf1f MÃ… |
517 | git format-patch --range-diff=HEAD~1 HEAD~1 >actual && |
518 | test_when_finished "rm 0001-*" && | |
519 | test_line_count = 1 actual && | |
520 | test_i18ngrep "^Range-diff:$" 0001-* && | |
521 | grep "> 1: .* new message" 0001-* | |
cdc067c3 DS |
522 | ' |
523 | ||
db91988a ZH |
524 | test_expect_success 'format-patch --range-diff reroll-count with a non-integer' ' |
525 | git format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual && | |
526 | test_when_finished "rm v2.9-0001-*" && | |
527 | test_line_count = 1 actual && | |
528 | test_i18ngrep "^Range-diff:$" v2.9-0001-* && | |
529 | grep "> 1: .* new message" v2.9-0001-* | |
530 | ' | |
531 | ||
532 | test_expect_success 'format-patch --range-diff reroll-count with a integer' ' | |
533 | git format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual && | |
534 | test_when_finished "rm v2-0001-*" && | |
535 | test_line_count = 1 actual && | |
536 | test_i18ngrep "^Range-diff ..* v1:$" v2-0001-* && | |
537 | grep "> 1: .* new message" v2-0001-* | |
538 | ' | |
539 | ||
540 | test_expect_success 'format-patch --range-diff with v0' ' | |
541 | git format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual && | |
542 | test_when_finished "rm v0-0001-*" && | |
543 | test_line_count = 1 actual && | |
544 | test_i18ngrep "^Range-diff:$" v0-0001-* && | |
545 | grep "> 1: .* new message" v0-0001-* | |
546 | ' | |
547 | ||
937b76ed JS |
548 | test_expect_success 'range-diff overrides diff.noprefix internally' ' |
549 | git -c diff.noprefix=true range-diff HEAD^... | |
550 | ' | |
551 | ||
8cf51561 VD |
552 | test_expect_success 'basic with modified format.pretty with suffix' ' |
553 | git -c format.pretty="format:commit %H%d%n" range-diff \ | |
d6c6b108 | 554 | main..topic main..unmodified |
8cf51561 VD |
555 | ' |
556 | ||
557 | test_expect_success 'basic with modified format.pretty without "commit "' ' | |
558 | git -c format.pretty="format:%H%n" range-diff \ | |
d6c6b108 | 559 | main..topic main..unmodified |
8cf51561 VD |
560 | ' |
561 | ||
3bdbdfb7 DL |
562 | test_expect_success 'range-diff compares notes by default' ' |
563 | git notes add -m "topic note" topic && | |
564 | git notes add -m "unmodified note" unmodified && | |
565 | test_when_finished git notes remove topic unmodified && | |
d6c6b108 | 566 | git range-diff --no-color main..topic main..unmodified \ |
3bdbdfb7 DL |
567 | >actual && |
568 | sed s/Z/\ /g >expect <<-EOF && | |
569 | 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/ | |
570 | 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/ | |
571 | 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/ | |
572 | 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/ | |
9f726e1b | 573 | @@ Commit message |
3bdbdfb7 | 574 | Z |
9f726e1b DL |
575 | Z |
576 | Z ## Notes ## | |
3bdbdfb7 DL |
577 | - topic note |
578 | + unmodified note | |
579 | Z | |
580 | Z ## file ## | |
581 | Z@@ file: A | |
582 | EOF | |
583 | test_cmp expect actual | |
584 | ' | |
585 | ||
bd361918 DL |
586 | test_expect_success 'range-diff with --no-notes' ' |
587 | git notes add -m "topic note" topic && | |
588 | git notes add -m "unmodified note" unmodified && | |
589 | test_when_finished git notes remove topic unmodified && | |
d6c6b108 | 590 | git range-diff --no-color --no-notes main..topic main..unmodified \ |
bd361918 DL |
591 | >actual && |
592 | cat >expect <<-EOF && | |
593 | 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/ | |
594 | 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/ | |
595 | 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/ | |
596 | 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/ | |
597 | EOF | |
598 | test_cmp expect actual | |
599 | ' | |
600 | ||
601 | test_expect_success 'range-diff with multiple --notes' ' | |
602 | git notes --ref=note1 add -m "topic note1" topic && | |
603 | git notes --ref=note1 add -m "unmodified note1" unmodified && | |
604 | test_when_finished git notes --ref=note1 remove topic unmodified && | |
605 | git notes --ref=note2 add -m "topic note2" topic && | |
606 | git notes --ref=note2 add -m "unmodified note2" unmodified && | |
607 | test_when_finished git notes --ref=note2 remove topic unmodified && | |
d6c6b108 | 608 | git range-diff --no-color --notes=note1 --notes=note2 main..topic main..unmodified \ |
bd361918 DL |
609 | >actual && |
610 | sed s/Z/\ /g >expect <<-EOF && | |
611 | 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/ | |
612 | 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/ | |
613 | 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/ | |
614 | 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/ | |
615 | @@ Commit message | |
616 | Z | |
617 | Z | |
618 | Z ## Notes (note1) ## | |
619 | - topic note1 | |
620 | + unmodified note1 | |
621 | Z | |
622 | Z | |
623 | Z ## Notes (note2) ## | |
624 | - topic note2 | |
625 | + unmodified note2 | |
626 | Z | |
627 | Z ## file ## | |
628 | Z@@ file: A | |
629 | EOF | |
630 | test_cmp expect actual | |
631 | ' | |
632 | ||
5b583e6a | 633 | test_expect_success 'format-patch --range-diff does not compare notes by default' ' |
3bdbdfb7 DL |
634 | git notes add -m "topic note" topic && |
635 | git notes add -m "unmodified note" unmodified && | |
636 | test_when_finished git notes remove topic unmodified && | |
637 | git format-patch --cover-letter --range-diff=$prev \ | |
d6c6b108 | 638 | main..unmodified >actual && |
3bdbdfb7 DL |
639 | test_when_finished "rm 000?-*" && |
640 | test_line_count = 5 actual && | |
641 | test_i18ngrep "^Range-diff:$" 0000-* && | |
642 | grep "= 1: .* s/5/A" 0000-* && | |
643 | grep "= 2: .* s/4/A" 0000-* && | |
644 | grep "= 3: .* s/11/B" 0000-* && | |
5b583e6a DL |
645 | grep "= 4: .* s/12/B" 0000-* && |
646 | ! grep "Notes" 0000-* && | |
647 | ! grep "note" 0000-* | |
648 | ' | |
649 | ||
650 | test_expect_success 'format-patch --range-diff with --no-notes' ' | |
651 | git notes add -m "topic note" topic && | |
652 | git notes add -m "unmodified note" unmodified && | |
653 | test_when_finished git notes remove topic unmodified && | |
654 | git format-patch --no-notes --cover-letter --range-diff=$prev \ | |
d6c6b108 | 655 | main..unmodified >actual && |
5b583e6a DL |
656 | test_when_finished "rm 000?-*" && |
657 | test_line_count = 5 actual && | |
658 | test_i18ngrep "^Range-diff:$" 0000-* && | |
659 | grep "= 1: .* s/5/A" 0000-* && | |
660 | grep "= 2: .* s/4/A" 0000-* && | |
661 | grep "= 3: .* s/11/B" 0000-* && | |
662 | grep "= 4: .* s/12/B" 0000-* && | |
663 | ! grep "Notes" 0000-* && | |
664 | ! grep "note" 0000-* | |
665 | ' | |
666 | ||
667 | test_expect_success 'format-patch --range-diff with --notes' ' | |
668 | git notes add -m "topic note" topic && | |
669 | git notes add -m "unmodified note" unmodified && | |
670 | test_when_finished git notes remove topic unmodified && | |
671 | git format-patch --notes --cover-letter --range-diff=$prev \ | |
d6c6b108 | 672 | main..unmodified >actual && |
5b583e6a DL |
673 | test_when_finished "rm 000?-*" && |
674 | test_line_count = 5 actual && | |
675 | test_i18ngrep "^Range-diff:$" 0000-* && | |
676 | grep "= 1: .* s/5/A" 0000-* && | |
677 | grep "= 2: .* s/4/A" 0000-* && | |
678 | grep "= 3: .* s/11/B" 0000-* && | |
3bdbdfb7 DL |
679 | grep "! 4: .* s/12/B" 0000-* && |
680 | sed s/Z/\ /g >expect <<-EOF && | |
9f726e1b | 681 | @@ Commit message |
3bdbdfb7 | 682 | Z |
9f726e1b DL |
683 | Z |
684 | Z ## Notes ## | |
3bdbdfb7 DL |
685 | - topic note |
686 | + unmodified note | |
687 | Z | |
688 | Z ## file ## | |
689 | Z@@ file: A | |
690 | EOF | |
9f726e1b | 691 | sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && |
3bdbdfb7 DL |
692 | test_cmp expect actual |
693 | ' | |
694 | ||
828765df | 695 | test_expect_success 'format-patch --range-diff with format.notes config' ' |
5b583e6a DL |
696 | git notes add -m "topic note" topic && |
697 | git notes add -m "unmodified note" unmodified && | |
698 | test_when_finished git notes remove topic unmodified && | |
699 | test_config format.notes true && | |
700 | git format-patch --cover-letter --range-diff=$prev \ | |
d6c6b108 | 701 | main..unmodified >actual && |
5b583e6a DL |
702 | test_when_finished "rm 000?-*" && |
703 | test_line_count = 5 actual && | |
704 | test_i18ngrep "^Range-diff:$" 0000-* && | |
705 | grep "= 1: .* s/5/A" 0000-* && | |
706 | grep "= 2: .* s/4/A" 0000-* && | |
707 | grep "= 3: .* s/11/B" 0000-* && | |
708 | grep "! 4: .* s/12/B" 0000-* && | |
709 | sed s/Z/\ /g >expect <<-EOF && | |
710 | @@ Commit message | |
711 | Z | |
712 | Z | |
713 | Z ## Notes ## | |
714 | - topic note | |
715 | + unmodified note | |
716 | Z | |
717 | Z ## file ## | |
718 | Z@@ file: A | |
719 | EOF | |
720 | sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && | |
721 | test_cmp expect actual | |
722 | ' | |
723 | ||
724 | test_expect_success 'format-patch --range-diff with multiple notes' ' | |
725 | git notes --ref=note1 add -m "topic note1" topic && | |
726 | git notes --ref=note1 add -m "unmodified note1" unmodified && | |
727 | test_when_finished git notes --ref=note1 remove topic unmodified && | |
728 | git notes --ref=note2 add -m "topic note2" topic && | |
729 | git notes --ref=note2 add -m "unmodified note2" unmodified && | |
730 | test_when_finished git notes --ref=note2 remove topic unmodified && | |
731 | git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \ | |
d6c6b108 | 732 | main..unmodified >actual && |
5b583e6a DL |
733 | test_when_finished "rm 000?-*" && |
734 | test_line_count = 5 actual && | |
735 | test_i18ngrep "^Range-diff:$" 0000-* && | |
736 | grep "= 1: .* s/5/A" 0000-* && | |
737 | grep "= 2: .* s/4/A" 0000-* && | |
738 | grep "= 3: .* s/11/B" 0000-* && | |
739 | grep "! 4: .* s/12/B" 0000-* && | |
740 | sed s/Z/\ /g >expect <<-EOF && | |
741 | @@ Commit message | |
742 | Z | |
743 | Z | |
744 | Z ## Notes (note1) ## | |
745 | - topic note1 | |
746 | + unmodified note1 | |
747 | Z | |
748 | Z | |
749 | Z ## Notes (note2) ## | |
750 | - topic note2 | |
751 | + unmodified note2 | |
752 | Z | |
753 | Z ## file ## | |
754 | Z@@ file: A | |
755 | EOF | |
756 | sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && | |
757 | test_cmp expect actual | |
758 | ' | |
759 | ||
1e79f973 JS |
760 | test_expect_success '--left-only/--right-only' ' |
761 | git switch --orphan left-right && | |
762 | test_commit first && | |
763 | test_commit unmatched && | |
764 | test_commit common && | |
765 | git switch -C left-right first && | |
766 | git cherry-pick common && | |
767 | ||
768 | git range-diff -s --left-only ...common >actual && | |
769 | head_oid=$(git rev-parse --short HEAD) && | |
770 | common_oid=$(git rev-parse --short common) && | |
771 | echo "1: $head_oid = 2: $common_oid common" >expect && | |
772 | test_cmp expect actual | |
773 | ' | |
774 | ||
04b1f1fd PB |
775 | test_expect_success 'submodule changes are shown irrespective of diff.submodule' ' |
776 | git init sub-repo && | |
777 | test_commit -C sub-repo sub-first && | |
778 | sub_oid1=$(git -C sub-repo rev-parse HEAD) && | |
779 | test_commit -C sub-repo sub-second && | |
780 | sub_oid2=$(git -C sub-repo rev-parse HEAD) && | |
781 | test_commit -C sub-repo sub-third && | |
782 | sub_oid3=$(git -C sub-repo rev-parse HEAD) && | |
783 | ||
784 | git checkout -b main-sub topic && | |
785 | git submodule add ./sub-repo sub && | |
786 | git -C sub checkout --detach sub-first && | |
787 | git commit -m "add sub" sub && | |
788 | sup_oid1=$(git rev-parse --short HEAD) && | |
789 | git checkout -b topic-sub && | |
790 | git -C sub checkout sub-second && | |
791 | git commit -m "change sub" sub && | |
792 | sup_oid2=$(git rev-parse --short HEAD) && | |
793 | git checkout -b modified-sub main-sub && | |
794 | git -C sub checkout sub-third && | |
795 | git commit -m "change sub" sub && | |
796 | sup_oid3=$(git rev-parse --short HEAD) && | |
797 | sup_oid0=$(test_oid __) && | |
798 | ||
799 | test_config diff.submodule log && | |
800 | git range-diff topic topic-sub modified-sub >actual && | |
801 | cat >expect <<-EOF && | |
802 | 1: $sup_oid1 = 1: $sup_oid1 add sub | |
803 | 2: $sup_oid2 < -: $sup_oid0 change sub | |
804 | -: $sup_oid0 > 2: $sup_oid3 change sub | |
805 | EOF | |
806 | test_cmp expect actual && | |
807 | test_config diff.submodule diff && | |
808 | git range-diff topic topic-sub modified-sub >actual && | |
809 | git range-diff --creation-factor=100 topic topic-sub modified-sub >actual && | |
810 | cat >expect <<-EOF && | |
811 | 1: $sup_oid1 = 1: $sup_oid1 add sub | |
812 | 2: $sup_oid2 ! 2: $sup_oid3 change sub | |
813 | @@ Commit message | |
814 | ## sub ## | |
815 | @@ | |
816 | -Subproject commit $sub_oid1 | |
817 | -+Subproject commit $sub_oid2 | |
818 | ++Subproject commit $sub_oid3 | |
819 | EOF | |
820 | test_cmp expect actual && | |
821 | test_config diff.submodule diff && | |
822 | git range-diff --creation-factor=100 topic topic-sub modified-sub >actual && | |
823 | test_cmp expect actual | |
824 | ' | |
825 | ||
8884cf15 | 826 | test_done |