##// END OF EJS Templates
py3: use lower-cased module 'email.message' in test-import.t
Yuya Nishihara -
r37484:abd9f5ec default
parent child Browse files
Show More
@@ -1,1919 +1,1919 b''
1 1 $ hg init a
2 2 $ mkdir a/d1
3 3 $ mkdir a/d1/d2
4 4 $ echo line 1 > a/a
5 5 $ echo line 1 > a/d1/d2/a
6 6 $ hg --cwd a ci -Ama
7 7 adding a
8 8 adding d1/d2/a
9 9
10 10 $ echo line 2 >> a/a
11 11 $ hg --cwd a ci -u someone -d '1 0' -m'second change'
12 12
13 13 import with no args:
14 14
15 15 $ hg --cwd a import
16 16 abort: need at least one patch to import
17 17 [255]
18 18
19 19 generate patches for the test
20 20
21 21 $ hg --cwd a export tip > exported-tip.patch
22 22 $ hg --cwd a diff -r0:1 > diffed-tip.patch
23 23
24 24
25 25 import exported patch
26 26 (this also tests that editor is not invoked, if the patch contains the
27 27 commit message and '--edit' is not specified)
28 28
29 29 $ hg clone -r0 a b
30 30 adding changesets
31 31 adding manifests
32 32 adding file changes
33 33 added 1 changesets with 2 changes to 2 files
34 34 new changesets 80971e65b431
35 35 updating to branch default
36 36 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
37 37 $ HGEDITOR=cat hg --cwd b import ../exported-tip.patch
38 38 applying ../exported-tip.patch
39 39
40 40 message and committer and date should be same
41 41
42 42 $ hg --cwd b tip
43 43 changeset: 1:1d4bd90af0e4
44 44 tag: tip
45 45 user: someone
46 46 date: Thu Jan 01 00:00:01 1970 +0000
47 47 summary: second change
48 48
49 49 $ rm -r b
50 50
51 51
52 52 import exported patch with external patcher
53 53 (this also tests that editor is invoked, if the '--edit' is specified,
54 54 regardless of the commit message in the patch)
55 55
56 56 $ cat > dummypatch.py <<EOF
57 57 > from __future__ import print_function
58 58 > print('patching file a')
59 59 > open('a', 'wb').write(b'line2\n')
60 60 > EOF
61 61 $ hg clone -r0 a b
62 62 adding changesets
63 63 adding manifests
64 64 adding file changes
65 65 added 1 changesets with 2 changes to 2 files
66 66 new changesets 80971e65b431
67 67 updating to branch default
68 68 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
69 69 $ HGEDITOR=cat hg --config ui.patch="$PYTHON ../dummypatch.py" --cwd b import --edit ../exported-tip.patch
70 70 applying ../exported-tip.patch
71 71 second change
72 72
73 73
74 74 HG: Enter commit message. Lines beginning with 'HG:' are removed.
75 75 HG: Leave message empty to abort commit.
76 76 HG: --
77 77 HG: user: someone
78 78 HG: branch 'default'
79 79 HG: changed a
80 80 $ cat b/a
81 81 line2
82 82 $ rm -r b
83 83
84 84
85 85 import of plain diff should fail without message
86 86 (this also tests that editor is invoked, if the patch doesn't contain
87 87 the commit message, regardless of '--edit')
88 88
89 89 $ hg clone -r0 a b
90 90 adding changesets
91 91 adding manifests
92 92 adding file changes
93 93 added 1 changesets with 2 changes to 2 files
94 94 new changesets 80971e65b431
95 95 updating to branch default
96 96 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
97 97 $ cat > $TESTTMP/editor.sh <<EOF
98 98 > env | grep HGEDITFORM
99 99 > cat \$1
100 100 > EOF
101 101 $ HGEDITOR="sh $TESTTMP/editor.sh" hg --cwd b import ../diffed-tip.patch
102 102 applying ../diffed-tip.patch
103 103 HGEDITFORM=import.normal.normal
104 104
105 105
106 106 HG: Enter commit message. Lines beginning with 'HG:' are removed.
107 107 HG: Leave message empty to abort commit.
108 108 HG: --
109 109 HG: user: test
110 110 HG: branch 'default'
111 111 HG: changed a
112 112 abort: empty commit message
113 113 [255]
114 114
115 115 Test avoiding editor invocation at applying the patch with --exact,
116 116 even if commit message is empty
117 117
118 118 $ echo a >> b/a
119 119 $ hg --cwd b commit -m ' '
120 120 $ hg --cwd b tip -T "{node}\n"
121 121 d8804f3f5396d800812f579c8452796a5993bdb2
122 122 $ hg --cwd b export -o ../empty-log.diff .
123 123 $ hg --cwd b update -q -C ".^1"
124 124 $ hg --cwd b --config extensions.strip= strip -q tip
125 125 $ HGEDITOR=cat hg --cwd b import --exact ../empty-log.diff
126 126 applying ../empty-log.diff
127 127 $ hg --cwd b tip -T "{node}\n"
128 128 d8804f3f5396d800812f579c8452796a5993bdb2
129 129
130 130 $ rm -r b
131 131
132 132
133 133 import of plain diff should be ok with message
134 134
135 135 $ hg clone -r0 a b
136 136 adding changesets
137 137 adding manifests
138 138 adding file changes
139 139 added 1 changesets with 2 changes to 2 files
140 140 new changesets 80971e65b431
141 141 updating to branch default
142 142 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
143 143 $ hg --cwd b import -mpatch ../diffed-tip.patch
144 144 applying ../diffed-tip.patch
145 145 $ rm -r b
146 146
147 147
148 148 import of plain diff with specific date and user
149 149 (this also tests that editor is not invoked, if
150 150 '--message'/'--logfile' is specified and '--edit' is not)
151 151
152 152 $ hg clone -r0 a b
153 153 adding changesets
154 154 adding manifests
155 155 adding file changes
156 156 added 1 changesets with 2 changes to 2 files
157 157 new changesets 80971e65b431
158 158 updating to branch default
159 159 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
160 160 $ hg --cwd b import -mpatch -d '1 0' -u 'user@nowhere.net' ../diffed-tip.patch
161 161 applying ../diffed-tip.patch
162 162 $ hg -R b tip -pv
163 163 changeset: 1:ca68f19f3a40
164 164 tag: tip
165 165 user: user@nowhere.net
166 166 date: Thu Jan 01 00:00:01 1970 +0000
167 167 files: a
168 168 description:
169 169 patch
170 170
171 171
172 172 diff -r 80971e65b431 -r ca68f19f3a40 a
173 173 --- a/a Thu Jan 01 00:00:00 1970 +0000
174 174 +++ b/a Thu Jan 01 00:00:01 1970 +0000
175 175 @@ -1,1 +1,2 @@
176 176 line 1
177 177 +line 2
178 178
179 179 $ rm -r b
180 180
181 181
182 182 import of plain diff should be ok with --no-commit
183 183 (this also tests that editor is not invoked, if '--no-commit' is
184 184 specified, regardless of '--edit')
185 185
186 186 $ hg clone -r0 a b
187 187 adding changesets
188 188 adding manifests
189 189 adding file changes
190 190 added 1 changesets with 2 changes to 2 files
191 191 new changesets 80971e65b431
192 192 updating to branch default
193 193 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
194 194 $ HGEDITOR=cat hg --cwd b import --no-commit --edit ../diffed-tip.patch
195 195 applying ../diffed-tip.patch
196 196 $ hg --cwd b diff --nodates
197 197 diff -r 80971e65b431 a
198 198 --- a/a
199 199 +++ b/a
200 200 @@ -1,1 +1,2 @@
201 201 line 1
202 202 +line 2
203 203 $ rm -r b
204 204
205 205
206 206 import of malformed plain diff should fail
207 207
208 208 $ hg clone -r0 a b
209 209 adding changesets
210 210 adding manifests
211 211 adding file changes
212 212 added 1 changesets with 2 changes to 2 files
213 213 new changesets 80971e65b431
214 214 updating to branch default
215 215 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
216 216 $ sed 's/1,1/foo/' < diffed-tip.patch > broken.patch
217 217 $ hg --cwd b import -mpatch ../broken.patch
218 218 applying ../broken.patch
219 219 abort: bad hunk #1
220 220 [255]
221 221 $ rm -r b
222 222
223 223
224 224 hg -R repo import
225 225 put the clone in a subdir - having a directory named "a"
226 226 used to hide a bug.
227 227
228 228 $ mkdir dir
229 229 $ hg clone -r0 a dir/b
230 230 adding changesets
231 231 adding manifests
232 232 adding file changes
233 233 added 1 changesets with 2 changes to 2 files
234 234 new changesets 80971e65b431
235 235 updating to branch default
236 236 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
237 237 $ cd dir
238 238 $ hg -R b import ../exported-tip.patch
239 239 applying ../exported-tip.patch
240 240 $ cd ..
241 241 $ rm -r dir
242 242
243 243
244 244 import from stdin
245 245
246 246 $ hg clone -r0 a b
247 247 adding changesets
248 248 adding manifests
249 249 adding file changes
250 250 added 1 changesets with 2 changes to 2 files
251 251 new changesets 80971e65b431
252 252 updating to branch default
253 253 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
254 254 $ hg --cwd b import - < exported-tip.patch
255 255 applying patch from stdin
256 256 $ rm -r b
257 257
258 258
259 259 import two patches in one stream
260 260
261 261 $ hg init b
262 262 $ hg --cwd a export 0:tip | hg --cwd b import -
263 263 applying patch from stdin
264 264 $ hg --cwd a id
265 265 1d4bd90af0e4 tip
266 266 $ hg --cwd b id
267 267 1d4bd90af0e4 tip
268 268 $ rm -r b
269 269
270 270
271 271 override commit message
272 272
273 273 $ hg clone -r0 a b
274 274 adding changesets
275 275 adding manifests
276 276 adding file changes
277 277 added 1 changesets with 2 changes to 2 files
278 278 new changesets 80971e65b431
279 279 updating to branch default
280 280 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
281 281 $ hg --cwd b import -m 'override' - < exported-tip.patch
282 282 applying patch from stdin
283 283 $ hg --cwd b tip | grep override
284 284 summary: override
285 285 $ rm -r b
286 286
287 287 $ cat > mkmsg.py <<EOF
288 > import email.Message, sys
289 > msg = email.Message.Message()
288 > import email.message, sys
289 > msg = email.message.Message()
290 290 > patch = open(sys.argv[1], 'rb').read()
291 291 > msg.set_payload('email commit message\n' + patch)
292 292 > msg['Subject'] = 'email patch'
293 293 > msg['From'] = 'email patcher'
294 294 > open(sys.argv[2], 'wb').write(msg.as_string())
295 295 > EOF
296 296
297 297
298 298 plain diff in email, subject, message body
299 299
300 300 $ hg clone -r0 a b
301 301 adding changesets
302 302 adding manifests
303 303 adding file changes
304 304 added 1 changesets with 2 changes to 2 files
305 305 new changesets 80971e65b431
306 306 updating to branch default
307 307 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
308 308 $ $PYTHON mkmsg.py diffed-tip.patch msg.patch
309 309 $ hg --cwd b import ../msg.patch
310 310 applying ../msg.patch
311 311 $ hg --cwd b tip | grep email
312 312 user: email patcher
313 313 summary: email patch
314 314 $ rm -r b
315 315
316 316
317 317 plain diff in email, no subject, message body
318 318
319 319 $ hg clone -r0 a b
320 320 adding changesets
321 321 adding manifests
322 322 adding file changes
323 323 added 1 changesets with 2 changes to 2 files
324 324 new changesets 80971e65b431
325 325 updating to branch default
326 326 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
327 327 $ grep -v '^Subject:' msg.patch | hg --cwd b import -
328 328 applying patch from stdin
329 329 $ rm -r b
330 330
331 331
332 332 plain diff in email, subject, no message body
333 333
334 334 $ hg clone -r0 a b
335 335 adding changesets
336 336 adding manifests
337 337 adding file changes
338 338 added 1 changesets with 2 changes to 2 files
339 339 new changesets 80971e65b431
340 340 updating to branch default
341 341 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
342 342 $ grep -v '^email ' msg.patch | hg --cwd b import -
343 343 applying patch from stdin
344 344 $ rm -r b
345 345
346 346
347 347 plain diff in email, no subject, no message body, should fail
348 348
349 349 $ hg clone -r0 a b
350 350 adding changesets
351 351 adding manifests
352 352 adding file changes
353 353 added 1 changesets with 2 changes to 2 files
354 354 new changesets 80971e65b431
355 355 updating to branch default
356 356 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
357 357 $ egrep -v '^(Subject|email)' msg.patch | hg --cwd b import -
358 358 applying patch from stdin
359 359 abort: empty commit message
360 360 [255]
361 361 $ rm -r b
362 362
363 363
364 364 hg export in email, should use patch header
365 365
366 366 $ hg clone -r0 a b
367 367 adding changesets
368 368 adding manifests
369 369 adding file changes
370 370 added 1 changesets with 2 changes to 2 files
371 371 new changesets 80971e65b431
372 372 updating to branch default
373 373 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
374 374 $ $PYTHON mkmsg.py exported-tip.patch msg.patch
375 375 $ cat msg.patch | hg --cwd b import -
376 376 applying patch from stdin
377 377 $ hg --cwd b tip | grep second
378 378 summary: second change
379 379 $ rm -r b
380 380
381 381
382 382 subject: duplicate detection, removal of [PATCH]
383 383 The '---' tests the gitsendmail handling without proper mail headers
384 384
385 385 $ cat > mkmsg2.py <<EOF
386 > import email.Message, sys
387 > msg = email.Message.Message()
386 > import email.message, sys
387 > msg = email.message.Message()
388 388 > patch = open(sys.argv[1], 'rb').read()
389 389 > msg.set_payload('email patch\n\nnext line\n---\n' + patch)
390 390 > msg['Subject'] = '[PATCH] email patch'
391 391 > msg['From'] = 'email patcher'
392 392 > open(sys.argv[2], 'wb').write(msg.as_string())
393 393 > EOF
394 394
395 395
396 396 plain diff in email, [PATCH] subject, message body with subject
397 397
398 398 $ hg clone -r0 a b
399 399 adding changesets
400 400 adding manifests
401 401 adding file changes
402 402 added 1 changesets with 2 changes to 2 files
403 403 new changesets 80971e65b431
404 404 updating to branch default
405 405 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
406 406 $ $PYTHON mkmsg2.py diffed-tip.patch msg.patch
407 407 $ cat msg.patch | hg --cwd b import -
408 408 applying patch from stdin
409 409 $ hg --cwd b tip --template '{desc}\n'
410 410 email patch
411 411
412 412 next line
413 413 $ rm -r b
414 414
415 415
416 416 Issue963: Parent of working dir incorrect after import of multiple
417 417 patches and rollback
418 418
419 419 We weren't backing up the correct dirstate file when importing many
420 420 patches: import patch1 patch2; rollback
421 421
422 422 $ echo line 3 >> a/a
423 423 $ hg --cwd a ci -m'third change'
424 424 $ hg --cwd a export -o '../patch%R' 1 2
425 425 $ hg clone -qr0 a b
426 426 $ hg --cwd b parents --template 'parent: {rev}\n'
427 427 parent: 0
428 428 $ hg --cwd b import -v ../patch1 ../patch2
429 429 applying ../patch1
430 430 patching file a
431 431 committing files:
432 432 a
433 433 committing manifest
434 434 committing changelog
435 435 created 1d4bd90af0e4
436 436 applying ../patch2
437 437 patching file a
438 438 committing files:
439 439 a
440 440 committing manifest
441 441 committing changelog
442 442 created 6d019af21222
443 443 $ hg --cwd b rollback
444 444 repository tip rolled back to revision 0 (undo import)
445 445 working directory now based on revision 0
446 446 $ hg --cwd b parents --template 'parent: {rev}\n'
447 447 parent: 0
448 448
449 449 Test that "hg rollback" doesn't restore dirstate to one at the
450 450 beginning of the rolled back transaction in not-"parent-gone" case.
451 451
452 452 invoking pretxncommit hook will cause marking '.hg/dirstate' as a file
453 453 to be restored when rolling back, after DirstateTransactionPlan (see wiki
454 454 page for detail).
455 455
456 456 $ hg --cwd b branch -q foobar
457 457 $ hg --cwd b commit -m foobar
458 458 $ hg --cwd b update 0 -q
459 459 $ hg --cwd b import ../patch1 ../patch2 --config hooks.pretxncommit=true
460 460 applying ../patch1
461 461 applying ../patch2
462 462 $ hg --cwd b update -q 1
463 463 $ hg --cwd b rollback -q
464 464 $ hg --cwd b parents --template 'parent: {rev}\n'
465 465 parent: 1
466 466
467 467 $ hg --cwd b update -q -C 0
468 468 $ hg --cwd b --config extensions.strip= strip -q 1
469 469
470 470 Test visibility of in-memory dirstate changes inside transaction to
471 471 external process
472 472
473 473 $ echo foo > a/foo
474 474 $ hg --cwd a commit -A -m 'adding foo' foo
475 475 $ hg --cwd a export -o '../patch%R' 3
476 476
477 477 $ cat > $TESTTMP/checkvisibility.sh <<EOF
478 478 > echo "===="
479 479 > hg parents --template "VISIBLE {rev}:{node|short}\n"
480 480 > hg status -amr
481 481 > # test that pending changes are hidden
482 482 > unset HG_PENDING
483 483 > hg parents --template "ACTUAL {rev}:{node|short}\n"
484 484 > hg status -amr
485 485 > echo "===="
486 486 > EOF
487 487
488 488 == test visibility to external editor
489 489
490 490 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
491 491 ====
492 492 VISIBLE 0:80971e65b431
493 493 ACTUAL 0:80971e65b431
494 494 ====
495 495
496 496 $ HGEDITOR="sh $TESTTMP/checkvisibility.sh" hg --cwd b import -v --edit ../patch1 ../patch2 ../patch3
497 497 applying ../patch1
498 498 patching file a
499 499 ====
500 500 VISIBLE 0:80971e65b431
501 501 M a
502 502 ACTUAL 0:80971e65b431
503 503 M a
504 504 ====
505 505 committing files:
506 506 a
507 507 committing manifest
508 508 committing changelog
509 509 created 1d4bd90af0e4
510 510 applying ../patch2
511 511 patching file a
512 512 ====
513 513 VISIBLE 1:1d4bd90af0e4
514 514 M a
515 515 ACTUAL 0:80971e65b431
516 516 M a
517 517 ====
518 518 committing files:
519 519 a
520 520 committing manifest
521 521 committing changelog
522 522 created 6d019af21222
523 523 applying ../patch3
524 524 patching file foo
525 525 adding foo
526 526 ====
527 527 VISIBLE 2:6d019af21222
528 528 A foo
529 529 ACTUAL 0:80971e65b431
530 530 M a
531 531 ====
532 532 committing files:
533 533 foo
534 534 committing manifest
535 535 committing changelog
536 536 created 55e3f75b2378
537 537
538 538 $ hg --cwd b rollback -q
539 539
540 540 (content of file "a" is already changed and it should be recognized as
541 541 "M", even though dirstate is restored to one before "hg import")
542 542
543 543 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
544 544 ====
545 545 VISIBLE 0:80971e65b431
546 546 M a
547 547 ACTUAL 0:80971e65b431
548 548 M a
549 549 ====
550 550 $ hg --cwd b revert --no-backup a
551 551 $ rm -f b/foo
552 552
553 553 == test visibility to precommit external hook
554 554
555 555 $ cat >> b/.hg/hgrc <<EOF
556 556 > [hooks]
557 557 > precommit.visibility = sh $TESTTMP/checkvisibility.sh
558 558 > EOF
559 559
560 560 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
561 561 ====
562 562 VISIBLE 0:80971e65b431
563 563 ACTUAL 0:80971e65b431
564 564 ====
565 565
566 566 $ hg --cwd b import ../patch1 ../patch2 ../patch3
567 567 applying ../patch1
568 568 ====
569 569 VISIBLE 0:80971e65b431
570 570 M a
571 571 ACTUAL 0:80971e65b431
572 572 M a
573 573 ====
574 574 applying ../patch2
575 575 ====
576 576 VISIBLE 1:1d4bd90af0e4
577 577 M a
578 578 ACTUAL 0:80971e65b431
579 579 M a
580 580 ====
581 581 applying ../patch3
582 582 ====
583 583 VISIBLE 2:6d019af21222
584 584 A foo
585 585 ACTUAL 0:80971e65b431
586 586 M a
587 587 ====
588 588
589 589 $ hg --cwd b rollback -q
590 590 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
591 591 ====
592 592 VISIBLE 0:80971e65b431
593 593 M a
594 594 ACTUAL 0:80971e65b431
595 595 M a
596 596 ====
597 597 $ hg --cwd b revert --no-backup a
598 598 $ rm -f b/foo
599 599
600 600 $ cat >> b/.hg/hgrc <<EOF
601 601 > [hooks]
602 602 > precommit.visibility =
603 603 > EOF
604 604
605 605 == test visibility to pretxncommit external hook
606 606
607 607 $ cat >> b/.hg/hgrc <<EOF
608 608 > [hooks]
609 609 > pretxncommit.visibility = sh $TESTTMP/checkvisibility.sh
610 610 > EOF
611 611
612 612 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
613 613 ====
614 614 VISIBLE 0:80971e65b431
615 615 ACTUAL 0:80971e65b431
616 616 ====
617 617
618 618 $ hg --cwd b import ../patch1 ../patch2 ../patch3
619 619 applying ../patch1
620 620 ====
621 621 VISIBLE 0:80971e65b431
622 622 M a
623 623 ACTUAL 0:80971e65b431
624 624 M a
625 625 ====
626 626 applying ../patch2
627 627 ====
628 628 VISIBLE 1:1d4bd90af0e4
629 629 M a
630 630 ACTUAL 0:80971e65b431
631 631 M a
632 632 ====
633 633 applying ../patch3
634 634 ====
635 635 VISIBLE 2:6d019af21222
636 636 A foo
637 637 ACTUAL 0:80971e65b431
638 638 M a
639 639 ====
640 640
641 641 $ hg --cwd b rollback -q
642 642 $ (cd b && sh "$TESTTMP/checkvisibility.sh")
643 643 ====
644 644 VISIBLE 0:80971e65b431
645 645 M a
646 646 ACTUAL 0:80971e65b431
647 647 M a
648 648 ====
649 649 $ hg --cwd b revert --no-backup a
650 650 $ rm -f b/foo
651 651
652 652 $ cat >> b/.hg/hgrc <<EOF
653 653 > [hooks]
654 654 > pretxncommit.visibility =
655 655 > EOF
656 656
657 657 $ rm -r b
658 658
659 659
660 660 importing a patch in a subdirectory failed at the commit stage
661 661
662 662 $ echo line 2 >> a/d1/d2/a
663 663 $ hg --cwd a ci -u someoneelse -d '1 0' -m'subdir change'
664 664
665 665 hg import in a subdirectory
666 666
667 667 $ hg clone -r0 a b
668 668 adding changesets
669 669 adding manifests
670 670 adding file changes
671 671 added 1 changesets with 2 changes to 2 files
672 672 new changesets 80971e65b431
673 673 updating to branch default
674 674 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
675 675 $ hg --cwd a export tip > tmp
676 676 $ sed -e 's/d1\/d2\///' < tmp > subdir-tip.patch
677 677 $ dir=`pwd`
678 678 $ cd b/d1/d2 2>&1 > /dev/null
679 679 $ hg import ../../../subdir-tip.patch
680 680 applying ../../../subdir-tip.patch
681 681 $ cd "$dir"
682 682
683 683 message should be 'subdir change'
684 684 committer should be 'someoneelse'
685 685
686 686 $ hg --cwd b tip
687 687 changeset: 1:3577f5aea227
688 688 tag: tip
689 689 user: someoneelse
690 690 date: Thu Jan 01 00:00:01 1970 +0000
691 691 summary: subdir change
692 692
693 693
694 694 should be empty
695 695
696 696 $ hg --cwd b status
697 697
698 698
699 699 Test fuzziness (ambiguous patch location, fuzz=2)
700 700
701 701 $ hg init fuzzy
702 702 $ cd fuzzy
703 703 $ echo line1 > a
704 704 $ echo line0 >> a
705 705 $ echo line3 >> a
706 706 $ hg ci -Am adda
707 707 adding a
708 708 $ echo line1 > a
709 709 $ echo line2 >> a
710 710 $ echo line0 >> a
711 711 $ echo line3 >> a
712 712 $ hg ci -m change a
713 713 $ hg export tip > fuzzy-tip.patch
714 714 $ hg up -C 0
715 715 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
716 716 $ echo line1 > a
717 717 $ echo line0 >> a
718 718 $ echo line1 >> a
719 719 $ echo line0 >> a
720 720 $ hg ci -m brancha
721 721 created new head
722 722 $ hg import --config patch.fuzz=0 -v fuzzy-tip.patch
723 723 applying fuzzy-tip.patch
724 724 patching file a
725 725 Hunk #1 FAILED at 0
726 726 1 out of 1 hunks FAILED -- saving rejects to file a.rej
727 727 abort: patch failed to apply
728 728 [255]
729 729 $ hg import --no-commit -v fuzzy-tip.patch
730 730 applying fuzzy-tip.patch
731 731 patching file a
732 732 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
733 733 applied to working directory
734 734 $ hg revert -a
735 735 reverting a
736 736
737 737
738 738 import with --no-commit should have written .hg/last-message.txt
739 739
740 740 $ cat .hg/last-message.txt
741 741 change (no-eol)
742 742
743 743
744 744 test fuzziness with eol=auto
745 745
746 746 $ hg --config patch.eol=auto import --no-commit -v fuzzy-tip.patch
747 747 applying fuzzy-tip.patch
748 748 patching file a
749 749 Hunk #1 succeeded at 2 with fuzz 1 (offset 0 lines).
750 750 applied to working directory
751 751 $ cd ..
752 752
753 753
754 754 Test hunk touching empty files (issue906)
755 755
756 756 $ hg init empty
757 757 $ cd empty
758 758 $ touch a
759 759 $ touch b1
760 760 $ touch c1
761 761 $ echo d > d
762 762 $ hg ci -Am init
763 763 adding a
764 764 adding b1
765 765 adding c1
766 766 adding d
767 767 $ echo a > a
768 768 $ echo b > b1
769 769 $ hg mv b1 b2
770 770 $ echo c > c1
771 771 $ hg copy c1 c2
772 772 $ rm d
773 773 $ touch d
774 774 $ hg diff --git
775 775 diff --git a/a b/a
776 776 --- a/a
777 777 +++ b/a
778 778 @@ -0,0 +1,1 @@
779 779 +a
780 780 diff --git a/b1 b/b2
781 781 rename from b1
782 782 rename to b2
783 783 --- a/b1
784 784 +++ b/b2
785 785 @@ -0,0 +1,1 @@
786 786 +b
787 787 diff --git a/c1 b/c1
788 788 --- a/c1
789 789 +++ b/c1
790 790 @@ -0,0 +1,1 @@
791 791 +c
792 792 diff --git a/c1 b/c2
793 793 copy from c1
794 794 copy to c2
795 795 --- a/c1
796 796 +++ b/c2
797 797 @@ -0,0 +1,1 @@
798 798 +c
799 799 diff --git a/d b/d
800 800 --- a/d
801 801 +++ b/d
802 802 @@ -1,1 +0,0 @@
803 803 -d
804 804 $ hg ci -m empty
805 805 $ hg export --git tip > empty.diff
806 806 $ hg up -C 0
807 807 4 files updated, 0 files merged, 2 files removed, 0 files unresolved
808 808 $ hg import empty.diff
809 809 applying empty.diff
810 810 $ for name in a b1 b2 c1 c2 d; do
811 811 > echo % $name file
812 812 > test -f $name && cat $name
813 813 > done
814 814 % a file
815 815 a
816 816 % b1 file
817 817 % b2 file
818 818 b
819 819 % c1 file
820 820 c
821 821 % c2 file
822 822 c
823 823 % d file
824 824 $ cd ..
825 825
826 826
827 827 Test importing a patch ending with a binary file removal
828 828
829 829 $ hg init binaryremoval
830 830 $ cd binaryremoval
831 831 $ echo a > a
832 832 $ $PYTHON -c "open('b', 'wb').write(b'a\x00b')"
833 833 $ hg ci -Am addall
834 834 adding a
835 835 adding b
836 836 $ hg rm a
837 837 $ hg rm b
838 838 $ hg st
839 839 R a
840 840 R b
841 841 $ hg ci -m remove
842 842 $ hg export --git . > remove.diff
843 843 $ cat remove.diff | grep git
844 844 diff --git a/a b/a
845 845 diff --git a/b b/b
846 846 $ hg up -C 0
847 847 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
848 848 $ hg import remove.diff
849 849 applying remove.diff
850 850 $ hg manifest
851 851 $ cd ..
852 852
853 853
854 854 Issue927: test update+rename with common name
855 855
856 856 $ hg init t
857 857 $ cd t
858 858 $ touch a
859 859 $ hg ci -Am t
860 860 adding a
861 861 $ echo a > a
862 862
863 863 Here, bfile.startswith(afile)
864 864
865 865 $ hg copy a a2
866 866 $ hg ci -m copya
867 867 $ hg export --git tip > copy.diff
868 868 $ hg up -C 0
869 869 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
870 870 $ hg import copy.diff
871 871 applying copy.diff
872 872
873 873 a should contain an 'a'
874 874
875 875 $ cat a
876 876 a
877 877
878 878 and a2 should have duplicated it
879 879
880 880 $ cat a2
881 881 a
882 882 $ cd ..
883 883
884 884
885 885 test -p0
886 886
887 887 $ hg init p0
888 888 $ cd p0
889 889 $ echo a > a
890 890 $ hg ci -Am t
891 891 adding a
892 892 $ hg import -p foo
893 893 abort: invalid value 'foo' for option -p, expected int
894 894 [255]
895 895 $ hg import -p0 - << EOF
896 896 > foobar
897 897 > --- a Sat Apr 12 22:43:58 2008 -0400
898 898 > +++ a Sat Apr 12 22:44:05 2008 -0400
899 899 > @@ -1,1 +1,1 @@
900 900 > -a
901 901 > +bb
902 902 > EOF
903 903 applying patch from stdin
904 904 $ hg status
905 905 $ cat a
906 906 bb
907 907
908 908 test --prefix
909 909
910 910 $ mkdir -p dir/dir2
911 911 $ echo b > dir/dir2/b
912 912 $ hg ci -Am b
913 913 adding dir/dir2/b
914 914 $ hg import -p2 --prefix dir - << EOF
915 915 > foobar
916 916 > --- drop1/drop2/dir2/b
917 917 > +++ drop1/drop2/dir2/b
918 918 > @@ -1,1 +1,1 @@
919 919 > -b
920 920 > +cc
921 921 > EOF
922 922 applying patch from stdin
923 923 $ hg status
924 924 $ cat dir/dir2/b
925 925 cc
926 926 $ cd ..
927 927
928 928
929 929 test paths outside repo root
930 930
931 931 $ mkdir outside
932 932 $ touch outside/foo
933 933 $ hg init inside
934 934 $ cd inside
935 935 $ hg import - <<EOF
936 936 > diff --git a/a b/b
937 937 > rename from ../outside/foo
938 938 > rename to bar
939 939 > EOF
940 940 applying patch from stdin
941 941 abort: path contains illegal component: ../outside/foo
942 942 [255]
943 943 $ cd ..
944 944
945 945
946 946 test import with similarity and git and strip (issue295 et al.)
947 947
948 948 $ hg init sim
949 949 $ cd sim
950 950 $ echo 'this is a test' > a
951 951 $ hg ci -Ama
952 952 adding a
953 953 $ cat > ../rename.diff <<EOF
954 954 > diff --git a/foo/a b/foo/a
955 955 > deleted file mode 100644
956 956 > --- a/foo/a
957 957 > +++ /dev/null
958 958 > @@ -1,1 +0,0 @@
959 959 > -this is a test
960 960 > diff --git a/foo/b b/foo/b
961 961 > new file mode 100644
962 962 > --- /dev/null
963 963 > +++ b/foo/b
964 964 > @@ -0,0 +1,2 @@
965 965 > +this is a test
966 966 > +foo
967 967 > EOF
968 968 $ hg import --no-commit -v -s 1 ../rename.diff -p2
969 969 applying ../rename.diff
970 970 patching file a
971 971 patching file b
972 972 adding b
973 973 recording removal of a as rename to b (88% similar)
974 974 applied to working directory
975 975 $ echo 'mod b' > b
976 976 $ hg st -C
977 977 A b
978 978 a
979 979 R a
980 980 $ hg revert -a
981 981 undeleting a
982 982 forgetting b
983 983 $ cat b
984 984 mod b
985 985 $ rm b
986 986 $ hg import --no-commit -v -s 100 ../rename.diff -p2
987 987 applying ../rename.diff
988 988 patching file a
989 989 patching file b
990 990 adding b
991 991 applied to working directory
992 992 $ hg st -C
993 993 A b
994 994 R a
995 995 $ cd ..
996 996
997 997
998 998 Issue1495: add empty file from the end of patch
999 999
1000 1000 $ hg init addemptyend
1001 1001 $ cd addemptyend
1002 1002 $ touch a
1003 1003 $ hg addremove
1004 1004 adding a
1005 1005 $ hg ci -m "commit"
1006 1006 $ cat > a.patch <<EOF
1007 1007 > add a, b
1008 1008 > diff --git a/a b/a
1009 1009 > --- a/a
1010 1010 > +++ b/a
1011 1011 > @@ -0,0 +1,1 @@
1012 1012 > +a
1013 1013 > diff --git a/b b/b
1014 1014 > new file mode 100644
1015 1015 > EOF
1016 1016 $ hg import --no-commit a.patch
1017 1017 applying a.patch
1018 1018
1019 1019 apply a good patch followed by an empty patch (mainly to ensure
1020 1020 that dirstate is *not* updated when import crashes)
1021 1021 $ hg update -q -C .
1022 1022 $ rm b
1023 1023 $ touch empty.patch
1024 1024 $ hg import a.patch empty.patch
1025 1025 applying a.patch
1026 1026 applying empty.patch
1027 1027 transaction abort!
1028 1028 rollback completed
1029 1029 abort: empty.patch: no diffs found
1030 1030 [255]
1031 1031 $ hg tip --template '{rev} {desc|firstline}\n'
1032 1032 0 commit
1033 1033 $ hg -q status
1034 1034 M a
1035 1035 $ cd ..
1036 1036
1037 1037 create file when source is not /dev/null
1038 1038
1039 1039 $ cat > create.patch <<EOF
1040 1040 > diff -Naur proj-orig/foo proj-new/foo
1041 1041 > --- proj-orig/foo 1969-12-31 16:00:00.000000000 -0800
1042 1042 > +++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700
1043 1043 > @@ -0,0 +1,1 @@
1044 1044 > +a
1045 1045 > EOF
1046 1046
1047 1047 some people have patches like the following too
1048 1048
1049 1049 $ cat > create2.patch <<EOF
1050 1050 > diff -Naur proj-orig/foo proj-new/foo
1051 1051 > --- proj-orig/foo.orig 1969-12-31 16:00:00.000000000 -0800
1052 1052 > +++ proj-new/foo 2009-07-17 16:50:45.801368000 -0700
1053 1053 > @@ -0,0 +1,1 @@
1054 1054 > +a
1055 1055 > EOF
1056 1056 $ hg init oddcreate
1057 1057 $ cd oddcreate
1058 1058 $ hg import --no-commit ../create.patch
1059 1059 applying ../create.patch
1060 1060 $ cat foo
1061 1061 a
1062 1062 $ rm foo
1063 1063 $ hg revert foo
1064 1064 $ hg import --no-commit ../create2.patch
1065 1065 applying ../create2.patch
1066 1066 $ cat foo
1067 1067 a
1068 1068
1069 1069 $ cd ..
1070 1070
1071 1071 Issue1859: first line mistaken for email headers
1072 1072
1073 1073 $ hg init emailconfusion
1074 1074 $ cd emailconfusion
1075 1075 $ cat > a.patch <<EOF
1076 1076 > module: summary
1077 1077 >
1078 1078 > description
1079 1079 >
1080 1080 >
1081 1081 > diff -r 000000000000 -r 9b4c1e343b55 test.txt
1082 1082 > --- /dev/null
1083 1083 > +++ b/a
1084 1084 > @@ -0,0 +1,1 @@
1085 1085 > +a
1086 1086 > EOF
1087 1087 $ hg import -d '0 0' a.patch
1088 1088 applying a.patch
1089 1089 $ hg parents -v
1090 1090 changeset: 0:5a681217c0ad
1091 1091 tag: tip
1092 1092 user: test
1093 1093 date: Thu Jan 01 00:00:00 1970 +0000
1094 1094 files: a
1095 1095 description:
1096 1096 module: summary
1097 1097
1098 1098 description
1099 1099
1100 1100
1101 1101 $ cd ..
1102 1102
1103 1103
1104 1104 in commit message
1105 1105
1106 1106 $ hg init commitconfusion
1107 1107 $ cd commitconfusion
1108 1108 $ cat > a.patch <<EOF
1109 1109 > module: summary
1110 1110 >
1111 1111 > --- description
1112 1112 >
1113 1113 > diff --git a/a b/a
1114 1114 > new file mode 100644
1115 1115 > --- /dev/null
1116 1116 > +++ b/a
1117 1117 > @@ -0,0 +1,1 @@
1118 1118 > +a
1119 1119 > EOF
1120 1120 > hg import -d '0 0' a.patch
1121 1121 > hg parents -v
1122 1122 > cd ..
1123 1123 >
1124 1124 > echo '% tricky header splitting'
1125 1125 > cat > trickyheaders.patch <<EOF
1126 1126 > From: User A <user@a>
1127 1127 > Subject: [PATCH] from: tricky!
1128 1128 >
1129 1129 > # HG changeset patch
1130 1130 > # User User B
1131 1131 > # Date 1266264441 18000
1132 1132 > # Branch stable
1133 1133 > # Node ID f2be6a1170ac83bf31cb4ae0bad00d7678115bc0
1134 1134 > # Parent 0000000000000000000000000000000000000000
1135 1135 > from: tricky!
1136 1136 >
1137 1137 > That is not a header.
1138 1138 >
1139 1139 > diff -r 000000000000 -r f2be6a1170ac foo
1140 1140 > --- /dev/null
1141 1141 > +++ b/foo
1142 1142 > @@ -0,0 +1,1 @@
1143 1143 > +foo
1144 1144 > EOF
1145 1145 applying a.patch
1146 1146 changeset: 0:f34d9187897d
1147 1147 tag: tip
1148 1148 user: test
1149 1149 date: Thu Jan 01 00:00:00 1970 +0000
1150 1150 files: a
1151 1151 description:
1152 1152 module: summary
1153 1153
1154 1154
1155 1155 % tricky header splitting
1156 1156
1157 1157 $ hg init trickyheaders
1158 1158 $ cd trickyheaders
1159 1159 $ hg import -d '0 0' ../trickyheaders.patch
1160 1160 applying ../trickyheaders.patch
1161 1161 $ hg export --git tip
1162 1162 # HG changeset patch
1163 1163 # User User B
1164 1164 # Date 0 0
1165 1165 # Thu Jan 01 00:00:00 1970 +0000
1166 1166 # Node ID eb56ab91903632294ac504838508cb370c0901d2
1167 1167 # Parent 0000000000000000000000000000000000000000
1168 1168 from: tricky!
1169 1169
1170 1170 That is not a header.
1171 1171
1172 1172 diff --git a/foo b/foo
1173 1173 new file mode 100644
1174 1174 --- /dev/null
1175 1175 +++ b/foo
1176 1176 @@ -0,0 +1,1 @@
1177 1177 +foo
1178 1178 $ cd ..
1179 1179
1180 1180
1181 1181 Issue2102: hg export and hg import speak different languages
1182 1182
1183 1183 $ hg init issue2102
1184 1184 $ cd issue2102
1185 1185 $ mkdir -p src/cmd/gc
1186 1186 $ touch src/cmd/gc/mksys.bash
1187 1187 $ hg ci -Am init
1188 1188 adding src/cmd/gc/mksys.bash
1189 1189 $ hg import - <<EOF
1190 1190 > # HG changeset patch
1191 1191 > # User Rob Pike
1192 1192 > # Date 1216685449 25200
1193 1193 > # Node ID 03aa2b206f499ad6eb50e6e207b9e710d6409c98
1194 1194 > # Parent 93d10138ad8df586827ca90b4ddb5033e21a3a84
1195 1195 > help management of empty pkg and lib directories in perforce
1196 1196 >
1197 1197 > R=gri
1198 1198 > DELTA=4 (4 added, 0 deleted, 0 changed)
1199 1199 > OCL=13328
1200 1200 > CL=13328
1201 1201 >
1202 1202 > diff --git a/lib/place-holder b/lib/place-holder
1203 1203 > new file mode 100644
1204 1204 > --- /dev/null
1205 1205 > +++ b/lib/place-holder
1206 1206 > @@ -0,0 +1,2 @@
1207 1207 > +perforce does not maintain empty directories.
1208 1208 > +this file helps.
1209 1209 > diff --git a/pkg/place-holder b/pkg/place-holder
1210 1210 > new file mode 100644
1211 1211 > --- /dev/null
1212 1212 > +++ b/pkg/place-holder
1213 1213 > @@ -0,0 +1,2 @@
1214 1214 > +perforce does not maintain empty directories.
1215 1215 > +this file helps.
1216 1216 > diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
1217 1217 > old mode 100644
1218 1218 > new mode 100755
1219 1219 > EOF
1220 1220 applying patch from stdin
1221 1221
1222 1222 #if execbit
1223 1223
1224 1224 $ hg sum
1225 1225 parent: 1:d59915696727 tip
1226 1226 help management of empty pkg and lib directories in perforce
1227 1227 branch: default
1228 1228 commit: (clean)
1229 1229 update: (current)
1230 1230 phases: 2 draft
1231 1231
1232 1232 $ hg diff --git -c tip
1233 1233 diff --git a/lib/place-holder b/lib/place-holder
1234 1234 new file mode 100644
1235 1235 --- /dev/null
1236 1236 +++ b/lib/place-holder
1237 1237 @@ -0,0 +1,2 @@
1238 1238 +perforce does not maintain empty directories.
1239 1239 +this file helps.
1240 1240 diff --git a/pkg/place-holder b/pkg/place-holder
1241 1241 new file mode 100644
1242 1242 --- /dev/null
1243 1243 +++ b/pkg/place-holder
1244 1244 @@ -0,0 +1,2 @@
1245 1245 +perforce does not maintain empty directories.
1246 1246 +this file helps.
1247 1247 diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
1248 1248 old mode 100644
1249 1249 new mode 100755
1250 1250
1251 1251 #else
1252 1252
1253 1253 $ hg sum
1254 1254 parent: 1:28f089cc9ccc tip
1255 1255 help management of empty pkg and lib directories in perforce
1256 1256 branch: default
1257 1257 commit: (clean)
1258 1258 update: (current)
1259 1259 phases: 2 draft
1260 1260
1261 1261 $ hg diff --git -c tip
1262 1262 diff --git a/lib/place-holder b/lib/place-holder
1263 1263 new file mode 100644
1264 1264 --- /dev/null
1265 1265 +++ b/lib/place-holder
1266 1266 @@ -0,0 +1,2 @@
1267 1267 +perforce does not maintain empty directories.
1268 1268 +this file helps.
1269 1269 diff --git a/pkg/place-holder b/pkg/place-holder
1270 1270 new file mode 100644
1271 1271 --- /dev/null
1272 1272 +++ b/pkg/place-holder
1273 1273 @@ -0,0 +1,2 @@
1274 1274 +perforce does not maintain empty directories.
1275 1275 +this file helps.
1276 1276
1277 1277 /* The mode change for mksys.bash is missing here, because on platforms */
1278 1278 /* that don't support execbits, mode changes in patches are ignored when */
1279 1279 /* they are imported. This is obviously also the reason for why the hash */
1280 1280 /* in the created changeset is different to the one you see above the */
1281 1281 /* #else clause */
1282 1282
1283 1283 #endif
1284 1284 $ cd ..
1285 1285
1286 1286
1287 1287 diff lines looking like headers
1288 1288
1289 1289 $ hg init difflineslikeheaders
1290 1290 $ cd difflineslikeheaders
1291 1291 $ echo a >a
1292 1292 $ echo b >b
1293 1293 $ echo c >c
1294 1294 $ hg ci -Am1
1295 1295 adding a
1296 1296 adding b
1297 1297 adding c
1298 1298
1299 1299 $ echo "key: value" >>a
1300 1300 $ echo "key: value" >>b
1301 1301 $ echo "foo" >>c
1302 1302 $ hg ci -m2
1303 1303
1304 1304 $ hg up -C 0
1305 1305 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
1306 1306 $ hg diff --git -c1 >want
1307 1307 $ hg diff -c1 | hg import --no-commit -
1308 1308 applying patch from stdin
1309 1309 $ hg diff --git >have
1310 1310 $ diff want have
1311 1311 $ cd ..
1312 1312
1313 1313 import a unified diff with no lines of context (diff -U0)
1314 1314
1315 1315 $ hg init diffzero
1316 1316 $ cd diffzero
1317 1317 $ cat > f << EOF
1318 1318 > c2
1319 1319 > c4
1320 1320 > c5
1321 1321 > EOF
1322 1322 $ hg commit -Am0
1323 1323 adding f
1324 1324
1325 1325 $ hg import --no-commit - << EOF
1326 1326 > # HG changeset patch
1327 1327 > # User test
1328 1328 > # Date 0 0
1329 1329 > # Node ID f4974ab632f3dee767567b0576c0ec9a4508575c
1330 1330 > # Parent 8679a12a975b819fae5f7ad3853a2886d143d794
1331 1331 > 1
1332 1332 > diff -r 8679a12a975b -r f4974ab632f3 f
1333 1333 > --- a/f Thu Jan 01 00:00:00 1970 +0000
1334 1334 > +++ b/f Thu Jan 01 00:00:00 1970 +0000
1335 1335 > @@ -0,0 +1,1 @@
1336 1336 > +c1
1337 1337 > @@ -1,0 +3,1 @@
1338 1338 > +c3
1339 1339 > @@ -3,1 +4,0 @@
1340 1340 > -c5
1341 1341 > EOF
1342 1342 applying patch from stdin
1343 1343
1344 1344 $ cat f
1345 1345 c1
1346 1346 c2
1347 1347 c3
1348 1348 c4
1349 1349
1350 1350 $ cd ..
1351 1351
1352 1352 commit message that looks like a diff header (issue1879)
1353 1353
1354 1354 $ hg init headerlikemsg
1355 1355 $ cd headerlikemsg
1356 1356 $ touch empty
1357 1357 $ echo nonempty >> nonempty
1358 1358 $ hg ci -qAl - <<EOF
1359 1359 > blah blah
1360 1360 > diff blah
1361 1361 > blah blah
1362 1362 > EOF
1363 1363 $ hg --config diff.git=1 log -pv
1364 1364 changeset: 0:c6ef204ef767
1365 1365 tag: tip
1366 1366 user: test
1367 1367 date: Thu Jan 01 00:00:00 1970 +0000
1368 1368 files: empty nonempty
1369 1369 description:
1370 1370 blah blah
1371 1371 diff blah
1372 1372 blah blah
1373 1373
1374 1374
1375 1375 diff --git a/empty b/empty
1376 1376 new file mode 100644
1377 1377 diff --git a/nonempty b/nonempty
1378 1378 new file mode 100644
1379 1379 --- /dev/null
1380 1380 +++ b/nonempty
1381 1381 @@ -0,0 +1,1 @@
1382 1382 +nonempty
1383 1383
1384 1384
1385 1385 (without --git, empty file is lost, but commit message should be preserved)
1386 1386
1387 1387 $ hg init plain
1388 1388 $ hg export 0 | hg -R plain import -
1389 1389 applying patch from stdin
1390 1390 $ hg --config diff.git=1 -R plain log -pv
1391 1391 changeset: 0:60a2d231e71f
1392 1392 tag: tip
1393 1393 user: test
1394 1394 date: Thu Jan 01 00:00:00 1970 +0000
1395 1395 files: nonempty
1396 1396 description:
1397 1397 blah blah
1398 1398 diff blah
1399 1399 blah blah
1400 1400
1401 1401
1402 1402 diff --git a/nonempty b/nonempty
1403 1403 new file mode 100644
1404 1404 --- /dev/null
1405 1405 +++ b/nonempty
1406 1406 @@ -0,0 +1,1 @@
1407 1407 +nonempty
1408 1408
1409 1409
1410 1410 (with --git, patch contents should be fully preserved)
1411 1411
1412 1412 $ hg init git
1413 1413 $ hg --config diff.git=1 export 0 | hg -R git import -
1414 1414 applying patch from stdin
1415 1415 $ hg --config diff.git=1 -R git log -pv
1416 1416 changeset: 0:c6ef204ef767
1417 1417 tag: tip
1418 1418 user: test
1419 1419 date: Thu Jan 01 00:00:00 1970 +0000
1420 1420 files: empty nonempty
1421 1421 description:
1422 1422 blah blah
1423 1423 diff blah
1424 1424 blah blah
1425 1425
1426 1426
1427 1427 diff --git a/empty b/empty
1428 1428 new file mode 100644
1429 1429 diff --git a/nonempty b/nonempty
1430 1430 new file mode 100644
1431 1431 --- /dev/null
1432 1432 +++ b/nonempty
1433 1433 @@ -0,0 +1,1 @@
1434 1434 +nonempty
1435 1435
1436 1436
1437 1437 $ cd ..
1438 1438
1439 1439 no segfault while importing a unified diff which start line is zero but chunk
1440 1440 size is non-zero
1441 1441
1442 1442 $ hg init startlinezero
1443 1443 $ cd startlinezero
1444 1444 $ echo foo > foo
1445 1445 $ hg commit -Amfoo
1446 1446 adding foo
1447 1447
1448 1448 $ hg import --no-commit - << EOF
1449 1449 > diff a/foo b/foo
1450 1450 > --- a/foo
1451 1451 > +++ b/foo
1452 1452 > @@ -0,1 +0,1 @@
1453 1453 > foo
1454 1454 > EOF
1455 1455 applying patch from stdin
1456 1456
1457 1457 $ cd ..
1458 1458
1459 1459 Test corner case involving fuzz and skew
1460 1460
1461 1461 $ hg init morecornercases
1462 1462 $ cd morecornercases
1463 1463
1464 1464 $ cat > 01-no-context-beginning-of-file.diff <<EOF
1465 1465 > diff --git a/a b/a
1466 1466 > --- a/a
1467 1467 > +++ b/a
1468 1468 > @@ -1,0 +1,1 @@
1469 1469 > +line
1470 1470 > EOF
1471 1471
1472 1472 $ cat > 02-no-context-middle-of-file.diff <<EOF
1473 1473 > diff --git a/a b/a
1474 1474 > --- a/a
1475 1475 > +++ b/a
1476 1476 > @@ -1,1 +1,1 @@
1477 1477 > -2
1478 1478 > +add some skew
1479 1479 > @@ -2,0 +2,1 @@
1480 1480 > +line
1481 1481 > EOF
1482 1482
1483 1483 $ cat > 03-no-context-end-of-file.diff <<EOF
1484 1484 > diff --git a/a b/a
1485 1485 > --- a/a
1486 1486 > +++ b/a
1487 1487 > @@ -10,0 +10,1 @@
1488 1488 > +line
1489 1489 > EOF
1490 1490
1491 1491 $ cat > 04-middle-of-file-completely-fuzzed.diff <<EOF
1492 1492 > diff --git a/a b/a
1493 1493 > --- a/a
1494 1494 > +++ b/a
1495 1495 > @@ -1,1 +1,1 @@
1496 1496 > -2
1497 1497 > +add some skew
1498 1498 > @@ -2,2 +2,3 @@
1499 1499 > not matching, should fuzz
1500 1500 > ... a bit
1501 1501 > +line
1502 1502 > EOF
1503 1503
1504 1504 $ cat > a <<EOF
1505 1505 > 1
1506 1506 > 2
1507 1507 > 3
1508 1508 > 4
1509 1509 > EOF
1510 1510 $ hg ci -Am adda a
1511 1511 $ for p in *.diff; do
1512 1512 > hg import -v --no-commit $p
1513 1513 > cat a
1514 1514 > hg revert -aqC a
1515 1515 > # patch -p1 < $p
1516 1516 > # cat a
1517 1517 > # hg revert -aC a
1518 1518 > done
1519 1519 applying 01-no-context-beginning-of-file.diff
1520 1520 patching file a
1521 1521 applied to working directory
1522 1522 1
1523 1523 line
1524 1524 2
1525 1525 3
1526 1526 4
1527 1527 applying 02-no-context-middle-of-file.diff
1528 1528 patching file a
1529 1529 Hunk #1 succeeded at 2 (offset 1 lines).
1530 1530 Hunk #2 succeeded at 4 (offset 1 lines).
1531 1531 applied to working directory
1532 1532 1
1533 1533 add some skew
1534 1534 3
1535 1535 line
1536 1536 4
1537 1537 applying 03-no-context-end-of-file.diff
1538 1538 patching file a
1539 1539 Hunk #1 succeeded at 5 (offset -6 lines).
1540 1540 applied to working directory
1541 1541 1
1542 1542 2
1543 1543 3
1544 1544 4
1545 1545 line
1546 1546 applying 04-middle-of-file-completely-fuzzed.diff
1547 1547 patching file a
1548 1548 Hunk #1 succeeded at 2 (offset 1 lines).
1549 1549 Hunk #2 succeeded at 5 with fuzz 2 (offset 1 lines).
1550 1550 applied to working directory
1551 1551 1
1552 1552 add some skew
1553 1553 3
1554 1554 4
1555 1555 line
1556 1556 $ cd ..
1557 1557
1558 1558 Test partial application
1559 1559 ------------------------
1560 1560
1561 1561 prepare a stack of patches depending on each other
1562 1562
1563 1563 $ hg init partial
1564 1564 $ cd partial
1565 1565 $ cat << EOF > a
1566 1566 > one
1567 1567 > two
1568 1568 > three
1569 1569 > four
1570 1570 > five
1571 1571 > six
1572 1572 > seven
1573 1573 > EOF
1574 1574 $ hg add a
1575 1575 $ echo 'b' > b
1576 1576 $ hg add b
1577 1577 $ hg commit -m 'initial' -u Babar
1578 1578 $ cat << EOF > a
1579 1579 > one
1580 1580 > two
1581 1581 > 3
1582 1582 > four
1583 1583 > five
1584 1584 > six
1585 1585 > seven
1586 1586 > EOF
1587 1587 $ hg commit -m 'three' -u Celeste
1588 1588 $ cat << EOF > a
1589 1589 > one
1590 1590 > two
1591 1591 > 3
1592 1592 > 4
1593 1593 > five
1594 1594 > six
1595 1595 > seven
1596 1596 > EOF
1597 1597 $ hg commit -m 'four' -u Rataxes
1598 1598 $ cat << EOF > a
1599 1599 > one
1600 1600 > two
1601 1601 > 3
1602 1602 > 4
1603 1603 > 5
1604 1604 > six
1605 1605 > seven
1606 1606 > EOF
1607 1607 $ echo bb >> b
1608 1608 $ hg commit -m 'five' -u Arthur
1609 1609 $ echo 'Babar' > jungle
1610 1610 $ hg add jungle
1611 1611 $ hg ci -m 'jungle' -u Zephir
1612 1612 $ echo 'Celeste' >> jungle
1613 1613 $ hg ci -m 'extended jungle' -u Cornelius
1614 1614 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1615 1615 @ extended jungle [Cornelius] 1: +1/-0
1616 1616 |
1617 1617 o jungle [Zephir] 1: +1/-0
1618 1618 |
1619 1619 o five [Arthur] 2: +2/-1
1620 1620 |
1621 1621 o four [Rataxes] 1: +1/-1
1622 1622 |
1623 1623 o three [Celeste] 1: +1/-1
1624 1624 |
1625 1625 o initial [Babar] 2: +8/-0
1626 1626
1627 1627 Adding those config options should not change the output of diffstat. Bugfix #4755.
1628 1628
1629 1629 $ hg log -r . --template '{diffstat}\n'
1630 1630 1: +1/-0
1631 1631 $ hg log -r . --template '{diffstat}\n' --config diff.git=1 \
1632 1632 > --config diff.noprefix=1
1633 1633 1: +1/-0
1634 1634
1635 1635 Importing with some success and some errors:
1636 1636
1637 1637 $ hg update --rev 'desc(initial)'
1638 1638 2 files updated, 0 files merged, 1 files removed, 0 files unresolved
1639 1639 $ hg export --rev 'desc(five)' | hg import --partial -
1640 1640 applying patch from stdin
1641 1641 patching file a
1642 1642 Hunk #1 FAILED at 1
1643 1643 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1644 1644 patch applied partially
1645 1645 (fix the .rej files and run `hg commit --amend`)
1646 1646 [1]
1647 1647
1648 1648 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1649 1649 @ five [Arthur] 1: +1/-0
1650 1650 |
1651 1651 | o extended jungle [Cornelius] 1: +1/-0
1652 1652 | |
1653 1653 | o jungle [Zephir] 1: +1/-0
1654 1654 | |
1655 1655 | o five [Arthur] 2: +2/-1
1656 1656 | |
1657 1657 | o four [Rataxes] 1: +1/-1
1658 1658 | |
1659 1659 | o three [Celeste] 1: +1/-1
1660 1660 |/
1661 1661 o initial [Babar] 2: +8/-0
1662 1662
1663 1663 $ hg export
1664 1664 # HG changeset patch
1665 1665 # User Arthur
1666 1666 # Date 0 0
1667 1667 # Thu Jan 01 00:00:00 1970 +0000
1668 1668 # Node ID 26e6446bb2526e2be1037935f5fca2b2706f1509
1669 1669 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1670 1670 five
1671 1671
1672 1672 diff -r 8e4f0351909e -r 26e6446bb252 b
1673 1673 --- a/b Thu Jan 01 00:00:00 1970 +0000
1674 1674 +++ b/b Thu Jan 01 00:00:00 1970 +0000
1675 1675 @@ -1,1 +1,2 @@
1676 1676 b
1677 1677 +bb
1678 1678 $ hg status -c .
1679 1679 C a
1680 1680 C b
1681 1681 $ ls
1682 1682 a
1683 1683 a.rej
1684 1684 b
1685 1685
1686 1686 Importing with zero success:
1687 1687
1688 1688 $ hg update --rev 'desc(initial)'
1689 1689 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1690 1690 $ hg export --rev 'desc(four)' | hg import --partial -
1691 1691 applying patch from stdin
1692 1692 patching file a
1693 1693 Hunk #1 FAILED at 0
1694 1694 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1695 1695 patch applied partially
1696 1696 (fix the .rej files and run `hg commit --amend`)
1697 1697 [1]
1698 1698
1699 1699 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1700 1700 @ four [Rataxes] 0: +0/-0
1701 1701 |
1702 1702 | o five [Arthur] 1: +1/-0
1703 1703 |/
1704 1704 | o extended jungle [Cornelius] 1: +1/-0
1705 1705 | |
1706 1706 | o jungle [Zephir] 1: +1/-0
1707 1707 | |
1708 1708 | o five [Arthur] 2: +2/-1
1709 1709 | |
1710 1710 | o four [Rataxes] 1: +1/-1
1711 1711 | |
1712 1712 | o three [Celeste] 1: +1/-1
1713 1713 |/
1714 1714 o initial [Babar] 2: +8/-0
1715 1715
1716 1716 $ hg export
1717 1717 # HG changeset patch
1718 1718 # User Rataxes
1719 1719 # Date 0 0
1720 1720 # Thu Jan 01 00:00:00 1970 +0000
1721 1721 # Node ID cb9b1847a74d9ad52e93becaf14b98dbcc274e1e
1722 1722 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1723 1723 four
1724 1724
1725 1725 $ hg status -c .
1726 1726 C a
1727 1727 C b
1728 1728 $ ls
1729 1729 a
1730 1730 a.rej
1731 1731 b
1732 1732
1733 1733 Importing with unknown file:
1734 1734
1735 1735 $ hg update --rev 'desc(initial)'
1736 1736 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1737 1737 $ hg export --rev 'desc("extended jungle")' | hg import --partial -
1738 1738 applying patch from stdin
1739 1739 unable to find 'jungle' for patching
1740 1740 (use '--prefix' to apply patch relative to the current directory)
1741 1741 1 out of 1 hunks FAILED -- saving rejects to file jungle.rej
1742 1742 patch applied partially
1743 1743 (fix the .rej files and run `hg commit --amend`)
1744 1744 [1]
1745 1745
1746 1746 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1747 1747 @ extended jungle [Cornelius] 0: +0/-0
1748 1748 |
1749 1749 | o four [Rataxes] 0: +0/-0
1750 1750 |/
1751 1751 | o five [Arthur] 1: +1/-0
1752 1752 |/
1753 1753 | o extended jungle [Cornelius] 1: +1/-0
1754 1754 | |
1755 1755 | o jungle [Zephir] 1: +1/-0
1756 1756 | |
1757 1757 | o five [Arthur] 2: +2/-1
1758 1758 | |
1759 1759 | o four [Rataxes] 1: +1/-1
1760 1760 | |
1761 1761 | o three [Celeste] 1: +1/-1
1762 1762 |/
1763 1763 o initial [Babar] 2: +8/-0
1764 1764
1765 1765 $ hg export
1766 1766 # HG changeset patch
1767 1767 # User Cornelius
1768 1768 # Date 0 0
1769 1769 # Thu Jan 01 00:00:00 1970 +0000
1770 1770 # Node ID 1fb1f86bef43c5a75918178f8d23c29fb0a7398d
1771 1771 # Parent 8e4f0351909eae6b9cf68c2c076cb54c42b54b2e
1772 1772 extended jungle
1773 1773
1774 1774 $ hg status -c .
1775 1775 C a
1776 1776 C b
1777 1777 $ ls
1778 1778 a
1779 1779 a.rej
1780 1780 b
1781 1781 jungle.rej
1782 1782
1783 1783 Importing multiple failing patches:
1784 1784
1785 1785 $ hg update --rev 'desc(initial)'
1786 1786 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1787 1787 $ echo 'B' > b # just to make another commit
1788 1788 $ hg commit -m "a new base"
1789 1789 created new head
1790 1790 $ hg export --rev 'desc("four") + desc("extended jungle")' | hg import --partial -
1791 1791 applying patch from stdin
1792 1792 patching file a
1793 1793 Hunk #1 FAILED at 0
1794 1794 1 out of 1 hunks FAILED -- saving rejects to file a.rej
1795 1795 patch applied partially
1796 1796 (fix the .rej files and run `hg commit --amend`)
1797 1797 [1]
1798 1798 $ hg log -G --template '{desc|firstline} [{author}] {diffstat}\n'
1799 1799 @ four [Rataxes] 0: +0/-0
1800 1800 |
1801 1801 o a new base [test] 1: +1/-1
1802 1802 |
1803 1803 | o extended jungle [Cornelius] 0: +0/-0
1804 1804 |/
1805 1805 | o four [Rataxes] 0: +0/-0
1806 1806 |/
1807 1807 | o five [Arthur] 1: +1/-0
1808 1808 |/
1809 1809 | o extended jungle [Cornelius] 1: +1/-0
1810 1810 | |
1811 1811 | o jungle [Zephir] 1: +1/-0
1812 1812 | |
1813 1813 | o five [Arthur] 2: +2/-1
1814 1814 | |
1815 1815 | o four [Rataxes] 1: +1/-1
1816 1816 | |
1817 1817 | o three [Celeste] 1: +1/-1
1818 1818 |/
1819 1819 o initial [Babar] 2: +8/-0
1820 1820
1821 1821 $ hg export
1822 1822 # HG changeset patch
1823 1823 # User Rataxes
1824 1824 # Date 0 0
1825 1825 # Thu Jan 01 00:00:00 1970 +0000
1826 1826 # Node ID a9d7b6d0ffbb4eb12b7d5939250fcd42e8930a1d
1827 1827 # Parent f59f8d2e95a8ca5b1b4ca64320140da85f3b44fd
1828 1828 four
1829 1829
1830 1830 $ hg status -c .
1831 1831 C a
1832 1832 C b
1833 1833
1834 1834 Importing some extra header
1835 1835 ===========================
1836 1836
1837 1837 $ cat > $TESTTMP/parseextra.py <<EOF
1838 1838 > import mercurial.patch
1839 1839 > import mercurial.cmdutil
1840 1840 >
1841 1841 > def processfoo(repo, data, extra, opts):
1842 1842 > if b'foo' in data:
1843 1843 > extra[b'foo'] = data[b'foo']
1844 1844 > def postimport(ctx):
1845 1845 > if b'foo' in ctx.extra():
1846 1846 > ctx.repo().ui.write(b'imported-foo: %s\n' % ctx.extra()[b'foo'])
1847 1847 >
1848 1848 > mercurial.patch.patchheadermap.append((b'Foo', b'foo'))
1849 1849 > mercurial.cmdutil.extrapreimport.append(b'foo')
1850 1850 > mercurial.cmdutil.extrapreimportmap[b'foo'] = processfoo
1851 1851 > mercurial.cmdutil.extrapostimport.append(b'foo')
1852 1852 > mercurial.cmdutil.extrapostimportmap[b'foo'] = postimport
1853 1853 > EOF
1854 1854 $ cat >> $HGRCPATH <<EOF
1855 1855 > [extensions]
1856 1856 > parseextra=$TESTTMP/parseextra.py
1857 1857 > EOF
1858 1858 $ hg up -C tip
1859 1859 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1860 1860 $ cat > $TESTTMP/foo.patch <<EOF
1861 1861 > # HG changeset patch
1862 1862 > # User Rataxes
1863 1863 > # Date 0 0
1864 1864 > # Thu Jan 01 00:00:00 1970 +0000
1865 1865 > # Foo bar
1866 1866 > height
1867 1867 >
1868 1868 > --- a/a Thu Jan 01 00:00:00 1970 +0000
1869 1869 > +++ b/a Wed Oct 07 09:17:44 2015 +0000
1870 1870 > @@ -5,3 +5,4 @@
1871 1871 > five
1872 1872 > six
1873 1873 > seven
1874 1874 > +heigt
1875 1875 > EOF
1876 1876 $ hg import $TESTTMP/foo.patch
1877 1877 applying $TESTTMP/foo.patch
1878 1878 imported-foo: bar
1879 1879 $ hg log --debug -r . | grep extra
1880 1880 extra: branch=default
1881 1881 extra: foo=bar
1882 1882
1883 1883 Warn the user that paths are relative to the root of
1884 1884 repository when file not found for patching
1885 1885
1886 1886 $ mkdir filedir
1887 1887 $ echo "file1" >> filedir/file1
1888 1888 $ hg add filedir/file1
1889 1889 $ hg commit -m "file1"
1890 1890 $ cd filedir
1891 1891 $ hg import -p 2 - <<EOF
1892 1892 > # HG changeset patch
1893 1893 > # User test
1894 1894 > # Date 0 0
1895 1895 > file2
1896 1896 >
1897 1897 > diff --git a/filedir/file1 b/filedir/file1
1898 1898 > --- a/filedir/file1
1899 1899 > +++ b/filedir/file1
1900 1900 > @@ -1,1 +1,2 @@
1901 1901 > file1
1902 1902 > +file2
1903 1903 > EOF
1904 1904 applying patch from stdin
1905 1905 unable to find 'file1' for patching
1906 1906 (use '--prefix' to apply patch relative to the current directory)
1907 1907 1 out of 1 hunks FAILED -- saving rejects to file file1.rej
1908 1908 abort: patch failed to apply
1909 1909 [255]
1910 1910
1911 1911 test import crash (issue5375)
1912 1912 $ cd ..
1913 1913 $ hg init repo
1914 1914 $ cd repo
1915 1915 $ printf "diff --git a/a b/b\nrename from a\nrename to b" | hg import -
1916 1916 applying patch from stdin
1917 1917 a not tracked!
1918 1918 abort: source file 'a' does not exist
1919 1919 [255]
General Comments 0
You need to be logged in to leave comments. Login now