Debian Codegraph @

tests/test-diff-unified.t

raw
1 $ hg init repo
2 $ cd repo
3 $ cat > a <<EOF
4 > c
5 > c
6 > a
7 > a
8 > b
9 > a
10 > a
11 > c
12 > c
13 > EOF
14 $ hg ci -Am adda
15 adding a
16
17 $ cat > a <<EOF
18 > c
19 > c
20 > a
21 > a
22 > dd
23 > a
24 > a
25 > c
26 > c
27 > EOF
28
29 default context
30
31 $ hg diff --nodates
32 diff -r cf9f4ba66af2 a
33 --- a/a
34 +++ b/a
35 @@ -2,7 +2,7 @@
36 c
37 a
38 a
39 -b
40 +dd
41 a
42 a
43 c
44
45 invalid --unified
46
47 $ hg diff --nodates -U foo
48 abort: diff context lines count must be an integer, not 'foo'
49 [10]
50
51
52 $ hg diff --nodates -U 2
53 diff -r cf9f4ba66af2 a
54 --- a/a
55 +++ b/a
56 @@ -3,5 +3,5 @@
57 a
58 a
59 -b
60 +dd
61 a
62 a
63
64 $ hg --config diff.unified=2 diff --nodates
65 diff -r cf9f4ba66af2 a
66 --- a/a
67 +++ b/a
68 @@ -3,5 +3,5 @@
69 a
70 a
71 -b
72 +dd
73 a
74 a
75
76 $ hg diff --nodates -U 1
77 diff -r cf9f4ba66af2 a
78 --- a/a
79 +++ b/a
80 @@ -4,3 +4,3 @@
81 a
82 -b
83 +dd
84 a
85
86 invalid diff.unified
87
88 $ hg --config diff.unified=foo diff --nodates
89 abort: diff context lines count must be an integer, not 'foo'
90 [10]
91
92 noprefix config and option
93
94 $ hg --config diff.noprefix=True diff --nodates
95 diff -r cf9f4ba66af2 a
96 --- a
97 +++ a
98 @@ -2,7 +2,7 @@
99 c
100 a
101 a
102 -b
103 +dd
104 a
105 a
106 c
107 $ hg diff --noprefix --nodates
108 diff -r cf9f4ba66af2 a
109 --- a
110 +++ a
111 @@ -2,7 +2,7 @@
112 c
113 a
114 a
115 -b
116 +dd
117 a
118 a
119 c
120
121 noprefix config disabled in plain mode, but option still enabled
122
123 $ HGPLAIN=1 hg --config diff.noprefix=True diff --nodates
124 diff -r cf9f4ba66af2 a
125 --- a/a
126 +++ b/a
127 @@ -2,7 +2,7 @@
128 c
129 a
130 a
131 -b
132 +dd
133 a
134 a
135 c
136 $ HGPLAIN=1 hg diff --noprefix --nodates
137 diff -r cf9f4ba66af2 a
138 --- a
139 +++ a
140 @@ -2,7 +2,7 @@
141 c
142 a
143 a
144 -b
145 +dd
146 a
147 a
148 c
149
150 $ cd ..
151
152
153 0 lines of context hunk header matches gnu diff hunk header
154
155 $ hg init diffzero
156 $ cd diffzero
157 $ cat > f1 << EOF
158 > c2
159 > c4
160 > c5
161 > EOF
162 $ hg commit -Am0
163 adding f1
164
165 $ cat > f2 << EOF
166 > c1
167 > c2
168 > c3
169 > c4
170 > EOF
171 $ mv f2 f1
172 $ hg diff -U0 --nodates
173 diff -r 55d8ff78db23 f1
174 --- a/f1
175 +++ b/f1
176 @@ -0,0 +1,1 @@
177 +c1
178 @@ -1,0 +3,1 @@
179 +c3
180 @@ -3,1 +4,0 @@
181 -c5
182
183 $ hg diff -U0 --nodates --git
184 diff --git a/f1 b/f1
185 --- a/f1
186 +++ b/f1
187 @@ -0,0 +1,1 @@
188 +c1
189 @@ -1,0 +3,1 @@
190 +c3
191 @@ -3,1 +4,0 @@
192 -c5
193
194 $ hg diff -U0 --nodates -p
195 diff -r 55d8ff78db23 f1
196 --- a/f1
197 +++ b/f1
198 @@ -0,0 +1,1 @@
199 +c1
200 @@ -1,0 +3,1 @@ c2
201 +c3
202 @@ -3,1 +4,0 @@ c4
203 -c5
204
205 $ echo a > f1
206 $ hg ci -m movef2
207
208 Test diff headers terminating with TAB when necessary (issue3357)
209 Regular diff --nodates, file creation
210
211 $ hg mv f1 'f 1'
212 $ echo b > 'f 1'
213 $ hg diff --nodates 'f 1'
214 diff -r 7574207d0d15 f 1
215 --- /dev/null
216 +++ b/f 1
217 @@ -0,0 +1,1 @@
218 +b
219
220 Git diff, adding space
221
222 $ hg diff --git
223 diff --git a/f1 b/f 1
224 rename from f1
225 rename to f 1
226 --- a/f1
227 +++ b/f 1
228 @@ -1,1 +1,1 @@
229 -a
230 +b
231
232 Git diff, adding extended headers
233
234 $ hg diff --git --config experimental.extendedheader.index=7 --config experimental.extendedheader.similarity=True
235 diff --git a/f1 b/f 1
236 similarity index 0%
237 rename from f1
238 rename to f 1
239 index 7898192..6178079 100644
240 --- a/f1
241 +++ b/f 1
242 @@ -1,1 +1,1 @@
243 -a
244 +b
245
246 $ hg diff --git --config experimental.extendedheader.index=-1
247 invalid length for extendedheader.index: '-1'
248 diff --git a/f1 b/f 1
249 rename from f1
250 rename to f 1
251 --- a/f1
252 +++ b/f 1
253 @@ -1,1 +1,1 @@
254 -a
255 +b
256
257 $ hg diff --git --config experimental.extendedheader.index=whatever
258 invalid value for extendedheader.index: 'whatever'
259 diff --git a/f1 b/f 1
260 rename from f1
261 rename to f 1
262 --- a/f1
263 +++ b/f 1
264 @@ -1,1 +1,1 @@
265 -a
266 +b
267
268 Git diff with noprefix
269
270 $ hg --config diff.noprefix=True diff --git --nodates
271 diff --git f1 f 1
272 rename from f1
273 rename to f 1
274 --- f1
275 +++ f 1
276 @@ -1,1 +1,1 @@
277 -a
278 +b
279
280 noprefix config disabled in plain mode, but option still enabled
281
282 $ HGPLAIN=1 hg --config diff.noprefix=True diff --git --nodates
283 diff --git a/f1 b/f 1
284 rename from f1
285 rename to f 1
286 --- a/f1
287 +++ b/f 1
288 @@ -1,1 +1,1 @@
289 -a
290 +b
291 $ HGPLAIN=1 hg diff --git --noprefix --nodates
292 diff --git f1 f 1
293 rename from f1
294 rename to f 1
295 --- f1
296 +++ f 1
297 @@ -1,1 +1,1 @@
298 -a
299 +b
300
301 Regular diff --nodates, file deletion
302
303 $ hg ci -m addspace
304 $ hg mv 'f 1' f1
305 $ echo a > f1
306 $ hg diff --nodates 'f 1'
307 diff -r ca50fe67c9c7 f 1
308 --- a/f 1
309 +++ /dev/null
310 @@ -1,1 +0,0 @@
311 -b
312
313 Git diff, removing space
314
315 $ hg diff --git
316 diff --git a/f 1 b/f1
317 rename from f 1
318 rename to f1
319 --- a/f 1
320 +++ b/f1
321 @@ -1,1 +1,1 @@
322 -b
323 +a
324
325 showfunc diff
326 $ cat > f1 << EOF
327 > int main() {
328 > int a = 0;
329 > int b = 1;
330 > int c = 2;
331 > int d = 3;
332 > return a + b + c + d;
333 > }
334 > EOF
335 $ hg commit -m addfunction
336 $ cat > f1 << EOF
337 > int main() {
338 > int a = 0;
339 > int b = 1;
340 > int c = 2;
341 > int e = 3;
342 > return a + b + c + e;
343 > }
344 > EOF
345 $ hg diff --git
346 diff --git a/f1 b/f1
347 --- a/f1
348 +++ b/f1
349 @@ -2,6 +2,6 @@
350 int a = 0;
351 int b = 1;
352 int c = 2;
353 - int d = 3;
354 - return a + b + c + d;
355 + int e = 3;
356 + return a + b + c + e;
357 }
358 $ hg diff --config diff.showfunc=True --git
359 diff --git a/f1 b/f1
360 --- a/f1
361 +++ b/f1
362 @@ -2,6 +2,6 @@ int main() {
363 int a = 0;
364 int b = 1;
365 int c = 2;
366 - int d = 3;
367 - return a + b + c + d;
368 + int e = 3;
369 + return a + b + c + e;
370 }
371
372 If [diff] git is set to true, but the user says --no-git, we should
373 *not* get git diffs
374 $ hg diff --nodates --config diff.git=1 --no-git
375 diff -r f2c7c817fa55 f1
376 --- a/f1
377 +++ b/f1
378 @@ -2,6 +2,6 @@
379 int a = 0;
380 int b = 1;
381 int c = 2;
382 - int d = 3;
383 - return a + b + c + d;
384 + int e = 3;
385 + return a + b + c + e;
386 }
387
388 showfunc diff with underscore or dollar sign prefix (issue6965)
389 $ cat > f1 << EOF
390 > int
391 > _rtld_main()
392 > {
393 > int a = 0;
394 > int b = 1;
395 > int c = 2;
396 > int d = 3;
397 > return a + b + c + d;
398 > }
399 >
400 > \$vms_quirk()
401 > {
402 > int a = 0;
403 > int b = 1;
404 > int c = 2;
405 > int d = 3;
406 > return a + b + c + d;
407 > }
408 > EOF
409 $ hg commit -m "add function bsd style"
410 $ cat > f1 << EOF
411 > int
412 > _rtld_main()
413 > {
414 > int a = 0;
415 > int b = 1;
416 > int c = 2;
417 > int e = 3;
418 > return a + b + c + e;
419 > }
420 >
421 > \$vms_quirk()
422 > {
423 > int a = 0;
424 > int b = 1;
425 > int c = 2;
426 > int e = 3;
427 > return a + b + c + e;
428 > }
429 > EOF
430 $ hg diff --nodates --config diff.showfunc=True
431 diff -r 21493d8e6bae f1
432 --- a/f1
433 +++ b/f1
434 @@ -4,8 +4,8 @@ _rtld_main()
435 int a = 0;
436 int b = 1;
437 int c = 2;
438 - int d = 3;
439 - return a + b + c + d;
440 + int e = 3;
441 + return a + b + c + e;
442 }
443
444 $vms_quirk()
445 @@ -13,6 +13,6 @@ $vms_quirk()
446 int a = 0;
447 int b = 1;
448 int c = 2;
449 - int d = 3;
450 - return a + b + c + d;
451 + int e = 3;
452 + return a + b + c + e;
453 }
454
455 $ cd ..
456
457 Long function names should be abbreviated, but multi-byte character shouldn't
458 be broken up
459
460 $ hg init longfunc
461 $ cd longfunc
462
463 >>> with open('a', 'wb') as f:
464 ... f.write(b'a' * 39 + b'bb' + b'\n') and None
465 ... f.write(b' .\n' * 3) and None
466 ... f.write(b' 0 b\n') and None
467 ... f.write(b' .\n' * 3) and None
468 ... f.write(b'a' * 39 + b'\xc3\xa0' + b'\n') and None
469 ... f.write(b' .\n' * 3) and None
470 ... f.write(b' 0 a with grave (single code point)\n') and None
471 ... f.write(b' .\n' * 3) and None
472 ... f.write(b'a' * 39 + b'a\xcc\x80' + b'\n') and None
473 ... f.write(b' .\n' * 3) and None
474 ... f.write(b' 0 a with grave (composition)\n') and None
475 ... f.write(b' .\n' * 3) and None
476 $ hg ci -qAm0
477
478 >>> with open('a', 'wb') as f:
479 ... f.write(b'a' * 39 + b'bb' + b'\n') and None
480 ... f.write(b' .\n' * 3) and None
481 ... f.write(b' 1 b\n') and None
482 ... f.write(b' .\n' * 3) and None
483 ... f.write(b'a' * 39 + b'\xc3\xa0' + b'\n') and None
484 ... f.write(b' .\n' * 3) and None
485 ... f.write(b' 1 a with grave (single code point)\n') and None
486 ... f.write(b' .\n' * 3) and None
487 ... f.write(b'a' * 39 + b'a\xcc\x80' + b'\n') and None
488 ... f.write(b' .\n' * 3) and None
489 ... f.write(b' 1 a with grave (composition)\n') and None
490 ... f.write(b' .\n' * 3) and None
491 $ hg ci -m1
492
493 $ hg diff -c1 --nodates --show-function
494 diff -r 3e92dd6fa812 -r a256341606cb a
495 --- a/a
496 +++ b/a
497 @@ -2,7 +2,7 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab
498 .
499 .
500 .
501 - 0 b
502 + 1 b
503 .
504 .
505 .
506 @@ -10,7 +10,7 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\xc3\xa0 (esc)
507 .
508 .
509 .
510 - 0 a with grave (single code point)
511 + 1 a with grave (single code point)
512 .
513 .
514 .
515 @@ -18,7 +18,7 @@ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\xcc\x80 (esc)
516 .
517 .
518 .
519 - 0 a with grave (composition)
520 + 1 a with grave (composition)
521 .
522 .
523 .
524
525 $ cd ..
526
527 Make sure `hg diff --git` differentiate "file did not exists" and "file is empty"
528 for git blob oids
529
530 $ hg init bloboids
531 $ cd bloboids
532
533 $ touch a
534 $ hg ci -Am "empty a"
535 adding a
536 $ hg diff -c 0 --git --config experimental.extendedheader.index=full | grep index
537 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644
538
539 Make sure `hg diff --git` differentiate "file was empty" and "file is removed"
540 for git blob oids
541
542 $ rm a
543 $ hg ci -Am "removed a"
544 removing a
545 $ hg diff -c 1 --git --config experimental.extendedheader.index=full | grep index
546 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 100644
547
548 $ cd ..