range-diff: add tests

These are essentially lifted from https://github.com/trast/tbdiff, with light touch-ups to account for the command now being named `git range-diff`. Apart from renaming `tbdiff` to `range-diff`, only one test case needed to be adjusted: 11 - 'changed message'. The underlying reason it had to be adjusted is that diff generation is sometimes ambiguous. In this case, a comment line and an empty line are added, but it is ambiguous whether they were added after the existing empty line, or whether an empty line and the comment line are added *before* the existing empty line. And apparently xdiff picks a different option here than Python's difflib. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Aug 13, 2018 at 04:33 UTC 8884cf15fb8ed83b2a1ec8bb91f060f20082b277
3 files changed +750
t/.gitattributes
+1
@@ -1,6 +1,7 @@
1 t[0-9][0-9][0-9][0-9]/* -whitespace
2 /diff-lib/* eol=lf
3 /t0110/url-* binary
4 +/t3206/* eol=lf
5 /t3900/*.txt eol=lf
6 /t3901/*.txt eol=lf
7 /t4034/*/* eol=lf
t/t3206-range-diff.sh new
+145
@@ -0,0 +1,145 @@
1 +#!/bin/sh
2 +
3 +test_description='range-diff tests'
4 +
5 +. ./test-lib.sh
6 +
7 +# Note that because of the range-diff's heuristics, test_commit does more
8 +# harm than good. We need some real history.
9 +
10 +test_expect_success 'setup' '
11 + git fast-import < "$TEST_DIRECTORY"/t3206/history.export
12 +'
13 +
14 +test_expect_success 'simple A..B A..C (unmodified)' '
15 + git range-diff --no-color master..topic master..unmodified \
16 + >actual &&
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/
22 + EOF
23 + test_cmp expected actual
24 +'
25 +
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
30 +'
31 +
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
36 +'
37 +
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/
45 + EOF
46 + test_cmp expected actual
47 +'
48 +
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/
56 + EOF
57 + test_cmp expected actual
58 +'
59 +
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/
68 + EOF
69 + test_cmp expected actual
70 +'
71 +
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/
79 + EOF
80 + test_cmp expected actual
81 +'
82 +
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/
92 + EOF
93 + test_cmp expected actual
94 +'
95 +
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/
102 + @@ -10,7 +10,7 @@
103 + 9
104 + 10
105 + -11
106 + -+B
107 + ++BB
108 + 12
109 + 13
110 + 14
111 + 4: a63e992 ! 4: d966c5c s/12/B/
112 + @@ -8,7 +8,7 @@
113 + @@
114 + 9
115 + 10
116 + - B
117 + + BB
118 + -12
119 + +B
120 + 13
121 + EOF
122 + test_cmp expected actual
123 +'
124 +
125 +test_expect_success 'changed message' '
126 + git range-diff --no-color topic...changed-message >actual &&
127 + sed s/Z/\ /g >expected <<-EOF &&
128 + 1: 4de457d = 1: f686024 s/5/A/
129 + 2: fccce22 ! 2: 4ab067d s/4/A/
130 + @@ -2,6 +2,8 @@
131 + Z
132 + Z s/4/A/
133 + Z
134 + + Also a silly comment here!
135 + +
136 + Zdiff --git a/file b/file
137 + Z--- a/file
138 + Z+++ b/file
139 + 3: 147e64e = 3: b9cb956 s/11/B/
140 + 4: a63e992 = 4: 8add5f1 s/12/B/
141 + EOF
142 + test_cmp expected actual
143 +'
144 +
145 +test_done
t/t3206/history.export new
+604
@@ -0,0 +1,604 @@
1 +blob
2 +mark :1
3 +data 51
4 +1
5 +2
6 +3
7 +4
8 +5
9 +6
10 +7
11 +8
12 +9
13 +10
14 +11
15 +12
16 +13
17 +14
18 +15
19 +16
20 +17
21 +18
22 +19
23 +20
24 +
25 +reset refs/heads/removed
26 +commit refs/heads/removed
27 +mark :2
28 +author Thomas Rast <trast@inf.ethz.ch> 1374424921 +0200
29 +committer Thomas Rast <trast@inf.ethz.ch> 1374484724 +0200
30 +data 8
31 +initial
32 +M 100644 :1 file
33 +
34 +blob
35 +mark :3
36 +data 51
37 +1
38 +2
39 +3
40 +4
41 +A
42 +6
43 +7
44 +8
45 +9
46 +10
47 +11
48 +12
49 +13
50 +14
51 +15
52 +16
53 +17
54 +18
55 +19
56 +20
57 +
58 +commit refs/heads/topic
59 +mark :4
60 +author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
61 +committer Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
62 +data 7
63 +s/5/A/
64 +from :2
65 +M 100644 :3 file
66 +
67 +blob
68 +mark :5
69 +data 51
70 +1
71 +2
72 +3
73 +A
74 +A
75 +6
76 +7
77 +8
78 +9
79 +10
80 +11
81 +12
82 +13
83 +14
84 +15
85 +16
86 +17
87 +18
88 +19
89 +20
90 +
91 +commit refs/heads/topic
92 +mark :6
93 +author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
94 +committer Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
95 +data 7
96 +s/4/A/
97 +from :4
98 +M 100644 :5 file
99 +
100 +blob
101 +mark :7
102 +data 50
103 +1
104 +2
105 +3
106 +A
107 +A
108 +6
109 +7
110 +8
111 +9
112 +10
113 +B
114 +12
115 +13
116 +14
117 +15
118 +16
119 +17
120 +18
121 +19
122 +20
123 +
124 +commit refs/heads/topic
125 +mark :8
126 +author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
127 +committer Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
128 +data 8
129 +s/11/B/
130 +from :6
131 +M 100644 :7 file
132 +
133 +blob
134 +mark :9
135 +data 49
136 +1
137 +2
138 +3
139 +A
140 +A
141 +6
142 +7
143 +8
144 +9
145 +10
146 +B
147 +B
148 +13
149 +14
150 +15
151 +16
152 +17
153 +18
154 +19
155 +20
156 +
157 +commit refs/heads/topic
158 +mark :10
159 +author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
160 +committer Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
161 +data 8
162 +s/12/B/
163 +from :8
164 +M 100644 :9 file
165 +
166 +blob
167 +mark :11
168 +data 10
169 +unrelated
170 +
171 +commit refs/heads/master
172 +mark :12
173 +author Thomas Rast <trast@inf.ethz.ch> 1374485127 +0200
174 +committer Thomas Rast <trast@inf.ethz.ch> 1374485127 +0200
175 +data 10
176 +unrelated
177 +from :2
178 +M 100644 :11 otherfile
179 +
180 +commit refs/heads/rebased
181 +mark :13
182 +author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
183 +committer Thomas Rast <trast@inf.ethz.ch> 1374485137 +0200
184 +data 7
185 +s/5/A/
186 +from :12
187 +M 100644 :3 file
188 +
189 +commit refs/heads/rebased
190 +mark :14
191 +author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
192 +committer Thomas Rast <trast@inf.ethz.ch> 1374485138 +0200
193 +data 7
194 +s/4/A/
195 +from :13
196 +M 100644 :5 file
197 +
198 +commit refs/heads/rebased
199 +mark :15
200 +author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
201 +committer Thomas Rast <trast@inf.ethz.ch> 1374485138 +0200
202 +data 8
203 +s/11/B/
204 +from :14
205 +M 100644 :7 file
206 +
207 +commit refs/heads/rebased
208 +mark :16
209 +author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
210 +committer Thomas Rast <trast@inf.ethz.ch> 1374485138 +0200
211 +data 8
212 +s/12/B/
213 +from :15
214 +M 100644 :9 file
215 +
216 +commit refs/heads/added
217 +mark :17
218 +author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
219 +committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
220 +data 7
221 +s/5/A/
222 +from :2
223 +M 100644 :3 file
224 +
225 +commit refs/heads/added
226 +mark :18
227 +author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
228 +committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
229 +data 7
230 +s/4/A/
231 +from :17
232 +M 100644 :5 file
233 +
234 +blob
235 +mark :19
236 +data 51
237 +1
238 +2
239 +3
240 +A
241 +A
242 +A
243 +7
244 +8
245 +9
246 +10
247 +11
248 +12
249 +13
250 +14
251 +15
252 +16
253 +17
254 +18
255 +19
256 +20
257 +
258 +commit refs/heads/added
259 +mark :20
260 +author Thomas Rast <trast@inf.ethz.ch> 1374485186 +0200
261 +committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
262 +data 7
263 +s/6/A/
264 +from :18
265 +M 100644 :19 file
266 +
267 +blob
268 +mark :21
269 +data 50
270 +1
271 +2
272 +3
273 +A
274 +A
275 +A
276 +7
277 +8
278 +9
279 +10
280 +B
281 +12
282 +13
283 +14
284 +15
285 +16
286 +17
287 +18
288 +19
289 +20
290 +
291 +commit refs/heads/added
292 +mark :22
293 +author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
294 +committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
295 +data 8
296 +s/11/B/
297 +from :20
298 +M 100644 :21 file
299 +
300 +blob
301 +mark :23
302 +data 49
303 +1
304 +2
305 +3
306 +A
307 +A
308 +A
309 +7
310 +8
311 +9
312 +10
313 +B
314 +B
315 +13
316 +14
317 +15
318 +16
319 +17
320 +18
321 +19
322 +20
323 +
324 +commit refs/heads/added
325 +mark :24
326 +author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
327 +committer Thomas Rast <trast@inf.ethz.ch> 1374485341 +0200
328 +data 8
329 +s/12/B/
330 +from :22
331 +M 100644 :23 file
332 +
333 +commit refs/heads/reordered
334 +mark :25
335 +author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
336 +committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
337 +data 7
338 +s/5/A/
339 +from :2
340 +M 100644 :3 file
341 +
342 +blob
343 +mark :26
344 +data 50
345 +1
346 +2
347 +3
348 +4
349 +A
350 +6
351 +7
352 +8
353 +9
354 +10
355 +B
356 +12
357 +13
358 +14
359 +15
360 +16
361 +17
362 +18
363 +19
364 +20
365 +
366 +commit refs/heads/reordered
367 +mark :27
368 +author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
369 +committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
370 +data 8
371 +s/11/B/
372 +from :25
373 +M 100644 :26 file
374 +
375 +blob
376 +mark :28
377 +data 49
378 +1
379 +2
380 +3
381 +4
382 +A
383 +6
384 +7
385 +8
386 +9
387 +10
388 +B
389 +B
390 +13
391 +14
392 +15
393 +16
394 +17
395 +18
396 +19
397 +20
398 +
399 +commit refs/heads/reordered
400 +mark :29
401 +author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
402 +committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
403 +data 8
404 +s/12/B/
405 +from :27
406 +M 100644 :28 file
407 +
408 +commit refs/heads/reordered
409 +mark :30
410 +author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
411 +committer Thomas Rast <trast@inf.ethz.ch> 1374485350 +0200
412 +data 7
413 +s/4/A/
414 +from :29
415 +M 100644 :9 file
416 +
417 +commit refs/heads/changed
418 +mark :31
419 +author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
420 +committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
421 +data 7
422 +s/5/A/
423 +from :2
424 +M 100644 :3 file
425 +
426 +commit refs/heads/changed
427 +mark :32
428 +author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
429 +committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
430 +data 7
431 +s/4/A/
432 +from :31
433 +M 100644 :5 file
434 +
435 +blob
436 +mark :33
437 +data 51
438 +1
439 +2
440 +3
441 +A
442 +A
443 +6
444 +7
445 +8
446 +9
447 +10
448 +BB
449 +12
450 +13
451 +14
452 +15
453 +16
454 +17
455 +18
456 +19
457 +20
458 +
459 +commit refs/heads/changed
460 +mark :34
461 +author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
462 +committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
463 +data 8
464 +s/11/B/
465 +from :32
466 +M 100644 :33 file
467 +
468 +blob
469 +mark :35
470 +data 50
471 +1
472 +2
473 +3
474 +A
475 +A
476 +6
477 +7
478 +8
479 +9
480 +10
481 +BB
482 +B
483 +13
484 +14
485 +15
486 +16
487 +17
488 +18
489 +19
490 +20
491 +
492 +commit refs/heads/changed
493 +mark :36
494 +author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
495 +committer Thomas Rast <trast@inf.ethz.ch> 1374485507 +0200
496 +data 8
497 +s/12/B/
498 +from :34
499 +M 100644 :35 file
500 +
501 +commit refs/heads/changed-message
502 +mark :37
503 +author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
504 +committer Thomas Rast <trast@inf.ethz.ch> 1374485530 +0200
505 +data 7
506 +s/5/A/
507 +from :2
508 +M 100644 :3 file
509 +
510 +commit refs/heads/changed-message
511 +mark :38
512 +author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
513 +committer Thomas Rast <trast@inf.ethz.ch> 1374485530 +0200
514 +data 35
515 +s/4/A/
516 +
517 +Also a silly comment here!
518 +from :37
519 +M 100644 :5 file
520 +
521 +commit refs/heads/changed-message
522 +mark :39
523 +author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
524 +committer Thomas Rast <trast@inf.ethz.ch> 1374485536 +0200
525 +data 8
526 +s/11/B/
527 +from :38
528 +M 100644 :7 file
529 +
530 +commit refs/heads/changed-message
531 +mark :40
532 +author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
533 +committer Thomas Rast <trast@inf.ethz.ch> 1374485536 +0200
534 +data 8
535 +s/12/B/
536 +from :39
537 +M 100644 :9 file
538 +
539 +commit refs/heads/unmodified
540 +mark :41
541 +author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
542 +committer Thomas Rast <trast@inf.ethz.ch> 1374485631 +0200
543 +data 7
544 +s/5/A/
545 +from :2
546 +M 100644 :3 file
547 +
548 +commit refs/heads/unmodified
549 +mark :42
550 +author Thomas Rast <trast@inf.ethz.ch> 1374485024 +0200
551 +committer Thomas Rast <trast@inf.ethz.ch> 1374485631 +0200
552 +data 7
553 +s/4/A/
554 +from :41
555 +M 100644 :5 file
556 +
557 +commit refs/heads/unmodified
558 +mark :43
559 +author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
560 +committer Thomas Rast <trast@inf.ethz.ch> 1374485632 +0200
561 +data 8
562 +s/11/B/
563 +from :42
564 +M 100644 :7 file
565 +
566 +commit refs/heads/unmodified
567 +mark :44
568 +author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
569 +committer Thomas Rast <trast@inf.ethz.ch> 1374485632 +0200
570 +data 8
571 +s/12/B/
572 +from :43
573 +M 100644 :9 file
574 +
575 +commit refs/heads/removed
576 +mark :45
577 +author Thomas Rast <trast@inf.ethz.ch> 1374485014 +0200
578 +committer Thomas Rast <trast@inf.ethz.ch> 1374486061 +0200
579 +data 7
580 +s/5/A/
581 +from :2
582 +M 100644 :3 file
583 +
584 +commit refs/heads/removed
585 +mark :46
586 +author Thomas Rast <trast@inf.ethz.ch> 1374485036 +0200
587 +committer Thomas Rast <trast@inf.ethz.ch> 1374486061 +0200
588 +data 8
589 +s/11/B/
590 +from :45
591 +M 100644 :26 file
592 +
593 +commit refs/heads/removed
594 +mark :47
595 +author Thomas Rast <trast@inf.ethz.ch> 1374485044 +0200
596 +committer Thomas Rast <trast@inf.ethz.ch> 1374486061 +0200
597 +data 8
598 +s/12/B/
599 +from :46
600 +M 100644 :28 file
601 +
602 +reset refs/heads/removed
603 +from :47
604 +