This instance will be upgraded to Heptapod 0.21.0rc2 on 2021-04-16 at 14:00 UTC+2 (a few minutes of down time)

test-commit-interactive.t 39.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Set up a repo

  $ cat <<EOF >> $HGRCPATH
  > [ui]
  > interactive = true
  > [extensions]
  > record =
  > EOF

  $ hg init a
  $ cd a

Select no files

  $ touch empty-rw
  $ hg add empty-rw

18 19 20 21 22
  $ hg record --config ui.interactive=false
  abort: running non-interactively, use commit instead
  [255]
  $ hg commit -i --config ui.interactive=false
  abort: running non-interactively
23
  [10]
24 25 26 27 28
  $ hg commit -i empty-rw<<EOF
  > n
  > EOF
  diff --git a/empty-rw b/empty-rw
  new file mode 100644
29
  abort: empty commit message
30
  [10]
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

  $ hg tip -p
  changeset:   -1:000000000000
  tag:         tip
  user:        
  date:        Thu Jan 01 00:00:00 1970 +0000
  
  

Select files but no hunks

  $ hg commit -i  empty-rw<<EOF
  > y
  > n
  > EOF
  diff --git a/empty-rw b/empty-rw
  new file mode 100644
  abort: empty commit message
49
  [10]
50 51 52 53 54 55 56 57 58

  $ hg tip -p
  changeset:   -1:000000000000
  tag:         tip
  user:        
  date:        Thu Jan 01 00:00:00 1970 +0000
  
  

59 60 61 62 63
Abort for untracked

  $ touch untracked
  $ hg commit -i -m should-fail empty-rw untracked
  abort: untracked: file not tracked!
64
  [10]
65 66
  $ rm untracked

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
Record empty file

  $ hg commit -i -d '0 0' -m empty empty-rw<<EOF
  > y
  > EOF
  diff --git a/empty-rw b/empty-rw
  new file mode 100644

  $ hg tip -p
  changeset:   0:c0708cf4e46e
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     empty
  
  

Summary shows we updated to the new cset

  $ hg summary
  parent: 0:c0708cf4e46e tip
   empty
  branch: default
  commit: (clean)
  update: (current)
92
  phases: 1 draft
93 94 95 96 97 98 99 100 101 102

Rename empty file

  $ hg mv empty-rw empty-rename
  $ hg commit -i -d '1 0' -m rename<<EOF
  > y
  > EOF
  diff --git a/empty-rw b/empty-rename
  rename from empty-rw
  rename to empty-rename
103 104
  examine changes to 'empty-rw' and 'empty-rename'?
  (enter ? for help) [Ynesfdaq?] y
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
  

  $ hg tip -p
  changeset:   1:d695e8dcb197
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:01 1970 +0000
  summary:     rename
  
  

Copy empty file

  $ hg cp empty-rename empty-copy
  $ hg commit -i -d '2 0' -m copy<<EOF
  > y
  > EOF
  diff --git a/empty-rename b/empty-copy
  copy from empty-rename
  copy to empty-copy
125 126
  examine changes to 'empty-rename' and 'empty-copy'?
  (enter ? for help) [Ynesfdaq?] y
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
  

  $ hg tip -p
  changeset:   2:1d4b90bea524
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:02 1970 +0000
  summary:     copy
  
  

Delete empty file

  $ hg rm empty-copy
  $ hg commit -i -d '3 0' -m delete<<EOF
  > y
  > EOF
  diff --git a/empty-copy b/empty-copy
  deleted file mode 100644
146 147
  examine changes to 'empty-copy'?
  (enter ? for help) [Ynesfdaq?] y
148 149 150 151 152 153 154 155 156 157 158 159 160
  

  $ hg tip -p
  changeset:   3:b39a238f01a1
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:03 1970 +0000
  summary:     delete
  
  

Add binary file

161
  $ hg bundle --type v1 --base -2 tip.bundle
162 163 164 165 166 167 168 169
  1 changesets found
  $ hg add tip.bundle
  $ hg commit -i -d '4 0' -m binary<<EOF
  > y
  > EOF
  diff --git a/tip.bundle b/tip.bundle
  new file mode 100644
  this is a binary file
170 171
  examine changes to 'tip.bundle'?
  (enter ? for help) [Ynesfdaq?] y
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
  

  $ hg tip -p
  changeset:   4:ad816da3711e
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:04 1970 +0000
  summary:     binary
  
  diff -r b39a238f01a1 -r ad816da3711e tip.bundle
  Binary file tip.bundle has changed
  

Change binary file

187
  $ hg bundle --base -2 --type v1 tip.bundle
188 189 190 191 192 193
  1 changesets found
  $ hg commit -i -d '5 0' -m binary-change<<EOF
  > y
  > EOF
  diff --git a/tip.bundle b/tip.bundle
  this modifies a binary file (all or nothing)
194 195
  examine changes to 'tip.bundle'?
  (enter ? for help) [Ynesfdaq?] y
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
  

  $ hg tip -p
  changeset:   5:dccd6f3eb485
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:05 1970 +0000
  summary:     binary-change
  
  diff -r ad816da3711e -r dccd6f3eb485 tip.bundle
  Binary file tip.bundle has changed
  

Rename and change binary file

  $ hg mv tip.bundle top.bundle
212
  $ hg bundle --base -2 --type v1 top.bundle
213 214 215 216 217 218 219 220
  1 changesets found
  $ hg commit -i -d '6 0' -m binary-change-rename<<EOF
  > y
  > EOF
  diff --git a/tip.bundle b/top.bundle
  rename from tip.bundle
  rename to top.bundle
  this modifies a binary file (all or nothing)
221 222
  examine changes to 'tip.bundle' and 'top.bundle'?
  (enter ? for help) [Ynesfdaq?] y
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
  

  $ hg tip -p
  changeset:   6:7fa44105f5b3
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:06 1970 +0000
  summary:     binary-change-rename
  
  diff -r dccd6f3eb485 -r 7fa44105f5b3 tip.bundle
  Binary file tip.bundle has changed
  diff -r dccd6f3eb485 -r 7fa44105f5b3 top.bundle
  Binary file top.bundle has changed
  

Add plain file

  $ for i in 1 2 3 4 5 6 7 8 9 10; do
  >     echo $i >> plain
  > done

  $ hg add plain
  $ hg commit -i -d '7 0' -m plain plain<<EOF
  > y
247
  > y
248 249 250
  > EOF
  diff --git a/plain b/plain
  new file mode 100644
251 252 253 254 255 256 257 258 259 260 261
  @@ -0,0 +1,10 @@
  +1
  +2
  +3
  +4
  +5
  +6
  +7
  +8
  +9
  +10
262 263
  record this change to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
264
  
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
  $ hg tip -p
  changeset:   7:11fb457c1be4
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:07 1970 +0000
  summary:     plain
  
  diff -r 7fa44105f5b3 -r 11fb457c1be4 plain
  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
  +++ b/plain	Thu Jan 01 00:00:07 1970 +0000
  @@ -0,0 +1,10 @@
  +1
  +2
  +3
  +4
  +5
  +6
  +7
  +8
  +9
  +10
  
Modify end of plain file with username unset

  $ echo 11 >> plain
  $ unset HGUSER
  $ hg commit -i --config ui.username= -d '8 0' -m end plain
  abort: no username supplied
293
  (use 'hg config --edit' to set your username)
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
  [255]


Modify end of plain file, also test that diffopts are accounted for

  $ HGUSER="test"
  $ export HGUSER
  $ hg commit -i --config diff.showfunc=true -d '8 0' -m end plain <<EOF
  > y
  > y
  > EOF
  diff --git a/plain b/plain
  1 hunks, 1 lines changed
  @@ -8,3 +8,4 @@ 7
   8
   9
   10
  +11
312 313
  record this change to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
314 315 316 317 318 319 320 321 322 323 324
  

Modify end of plain file, no EOL

  $ hg tip --template '{node}' >> plain
  $ hg commit -i -d '9 0' -m noeol plain <<EOF
  > y
  > y
  > EOF
  diff --git a/plain b/plain
  1 hunks, 1 lines changed
timeless's avatar
timeless committed
325
  @@ -9,3 +9,4 @@ 8
326 327 328 329 330
   9
   10
   11
  +7264f99c5f5ff3261504828afa4fb4d406c3af54
  \ No newline at end of file
331 332
  record this change to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
333 334
  

335 336
Record showfunc should preserve function across sections

337
  $ cat > f1.py <<NO_CHECK_EOF
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
  > def annotate(ui, repo, *pats, **opts):
  >     """show changeset information by line for each file
  > 
  >     List changes in files, showing the revision id responsible for
  >     each line.
  > 
  >     This command is useful for discovering when a change was made and
  >     by whom.
  > 
  >     If you include -f/-u/-d, the revision number is suppressed unless
  >     you also include -the revision number is suppressed unless
  >     you also include -n.
  > 
  >     Without the -a/--text option, annotate will avoid processing files
  >     it detects as binary. With -a, annotate will annotate the file
  >     anyway, although the results will probably be neither useful
  >     nor desirable.
  > 
  >     Returns 0 on success.
  >     """
  >     return 0
  > def archive(ui, repo, dest, **opts):
  >     '''create an unversioned archive of a repository revision
  > 
  >     By default, the revision used is the parent of the working
  >     directory; use -r/--rev to specify a different revision.
  > 
  >     The archive type is automatically detected based on file
  >     extension (to override, use -t/--type).
  > 
  >     .. container:: verbose
  > 
  >     Valid types are:
371
  > NO_CHECK_EOF
372 373
  $ hg add f1.py
  $ hg commit -m funcs
374
  $ cat > f1.py <<NO_CHECK_EOF
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
  > def annotate(ui, repo, *pats, **opts):
  >     """show changeset information by line for each file
  > 
  >     List changes in files, showing the revision id responsible for
  >     each line
  > 
  >     This command is useful for discovering when a change was made and
  >     by whom.
  > 
  >     Without the -a/--text option, annotate will avoid processing files
  >     it detects as binary. With -a, annotate will annotate the file
  >     anyway, although the results will probably be neither useful
  >     nor desirable.
  > 
  >     Returns 0 on success.
  >     """
  >     return 0
  > def archive(ui, repo, dest, **opts):
  >     '''create an unversioned archive of a repository revision
  > 
  >     By default, the revision used is the parent of the working
  >     directory; use -r/--rev to specify a different revision.
  > 
  >     The archive type is automatically detected based on file
  >     extension (or override using -t/--type).
  > 
  >     .. container:: verbose
  > 
  >     Valid types are:
404
  > NO_CHECK_EOF
405 406 407 408 409 410 411 412
  $ hg commit -i -m interactive <<EOF
  > y
  > y
  > y
  > y
  > EOF
  diff --git a/f1.py b/f1.py
  3 hunks, 6 lines changed
413 414
  examine changes to 'f1.py'?
  (enter ? for help) [Ynesfdaq?] y
415 416 417 418 419 420 421 422 423 424 425
  
  @@ -2,8 +2,8 @@ def annotate(ui, repo, *pats, **opts):
       """show changeset information by line for each file
   
       List changes in files, showing the revision id responsible for
  -    each line.
  +    each line
   
       This command is useful for discovering when a change was made and
       by whom.
   
426 427
  record change 1/3 to 'f1.py'?
  (enter ? for help) [Ynesfdaq?] y
428 429 430 431 432 433 434 435 436 437 438 439 440
  
  @@ -6,11 +6,7 @@ def annotate(ui, repo, *pats, **opts):
   
       This command is useful for discovering when a change was made and
       by whom.
   
  -    If you include -f/-u/-d, the revision number is suppressed unless
  -    you also include -the revision number is suppressed unless
  -    you also include -n.
  -
       Without the -a/--text option, annotate will avoid processing files
       it detects as binary. With -a, annotate will annotate the file
       anyway, although the results will probably be neither useful
441 442
  record change 2/3 to 'f1.py'?
  (enter ? for help) [Ynesfdaq?] y
443 444 445 446 447 448 449 450 451 452
  
  @@ -26,7 +22,7 @@ def archive(ui, repo, dest, **opts):
       directory; use -r/--rev to specify a different revision.
   
       The archive type is automatically detected based on file
  -    extension (to override, use -t/--type).
  +    extension (or override using -t/--type).
   
       .. container:: verbose
   
453 454
  record change 3/3 to 'f1.py'?
  (enter ? for help) [Ynesfdaq?] y
455 456
  

457 458 459 460 461 462 463 464 465
Modify end of plain file, add EOL

  $ echo >> plain
  $ echo 1 > plain2
  $ hg add plain2
  $ hg commit -i -d '10 0' -m eol plain plain2 <<EOF
  > y
  > y
  > y
466
  > y
467 468 469
  > EOF
  diff --git a/plain b/plain
  1 hunks, 1 lines changed
timeless's avatar
timeless committed
470
  @@ -9,4 +9,4 @@ 8
471 472 473 474 475 476
   9
   10
   11
  -7264f99c5f5ff3261504828afa4fb4d406c3af54
  \ No newline at end of file
  +7264f99c5f5ff3261504828afa4fb4d406c3af54
477 478
  record change 1/2 to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
479 480 481
  
  diff --git a/plain2 b/plain2
  new file mode 100644
482 483
  @@ -0,0 +1,1 @@
  +1
484 485
  record change 2/2 to 'plain2'?
  (enter ? for help) [Ynesfdaq?] y
486
  
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
Modify beginning, trim end, record both, add another file to test
changes numbering

  $ rm plain
  $ for i in 2 2 3 4 5 6 7 8 9 10; do
  >   echo $i >> plain
  > done
  $ echo 2 >> plain2

  $ hg commit -i -d '10 0' -m begin-and-end plain plain2 <<EOF
  > y
  > y
  > y
  > y
  > y
  > EOF
  diff --git a/plain b/plain
  2 hunks, 3 lines changed
  @@ -1,4 +1,4 @@
  -1
  +2
   2
   3
   4
511 512
  record change 1/3 to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
513
  
timeless's avatar
timeless committed
514
  @@ -8,5 +8,3 @@ 7
515 516 517 518 519
   8
   9
   10
  -11
  -7264f99c5f5ff3261504828afa4fb4d406c3af54
520 521
  record change 2/3 to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
522 523 524 525 526 527
  
  diff --git a/plain2 b/plain2
  1 hunks, 1 lines changed
  @@ -1,1 +1,2 @@
   1
  +2
528 529
  record change 3/3 to 'plain2'?
  (enter ? for help) [Ynesfdaq?] y
530 531 532
  

  $ hg tip -p
533
  changeset:   13:f941910cff62
534 535 536 537 538
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:10 1970 +0000
  summary:     begin-and-end
  
539
  diff -r 33abe24d946c -r f941910cff62 plain
540 541 542 543 544 545 546 547 548 549 550 551 552 553
  --- a/plain	Thu Jan 01 00:00:10 1970 +0000
  +++ b/plain	Thu Jan 01 00:00:10 1970 +0000
  @@ -1,4 +1,4 @@
  -1
  +2
   2
   3
   4
  @@ -8,5 +8,3 @@
   8
   9
   10
  -11
  -7264f99c5f5ff3261504828afa4fb4d406c3af54
554
  diff -r 33abe24d946c -r f941910cff62 plain2
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
  --- a/plain2	Thu Jan 01 00:00:10 1970 +0000
  +++ b/plain2	Thu Jan 01 00:00:10 1970 +0000
  @@ -1,1 +1,2 @@
   1
  +2
  

Trim beginning, modify end

  $ rm plain
  > for i in 4 5 6 7 8 9 10.new; do
  >   echo $i >> plain
  > done

Record end

  $ hg commit -i -d '11 0' -m end-only plain <<EOF
  > n
  > y
  > EOF
  diff --git a/plain b/plain
  2 hunks, 4 lines changed
  @@ -1,9 +1,6 @@
  -2
  -2
  -3
   4
   5
   6
   7
   8
   9
587 588
  record change 1/2 to 'plain'?
  (enter ? for help) [Ynesfdaq?] n
589 590 591 592 593 594 595 596 597 598
  
  @@ -4,7 +1,7 @@
   4
   5
   6
   7
   8
   9
  -10
  +10.new
599 600
  record change 2/2 to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
601 602 603
  

  $ hg tip -p
604
  changeset:   14:4915f538659b
605 606 607 608 609
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:11 1970 +0000
  summary:     end-only
  
610
  diff -r f941910cff62 -r 4915f538659b plain
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
  --- a/plain	Thu Jan 01 00:00:10 1970 +0000
  +++ b/plain	Thu Jan 01 00:00:11 1970 +0000
  @@ -7,4 +7,4 @@
   7
   8
   9
  -10
  +10.new
  

Record beginning

  $ hg commit -i -d '12 0' -m begin-only plain <<EOF
  > y
  > y
  > EOF
  diff --git a/plain b/plain
  1 hunks, 3 lines changed
  @@ -1,6 +1,3 @@
  -2
  -2
  -3
   4
   5
   6
636 637
  record this change to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
638 639 640
  

  $ hg tip -p
641
  changeset:   15:1b1f93d4b94b
642 643 644 645 646
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:12 1970 +0000
  summary:     begin-only
  
647
  diff -r 4915f538659b -r 1b1f93d4b94b plain
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
  --- a/plain	Thu Jan 01 00:00:11 1970 +0000
  +++ b/plain	Thu Jan 01 00:00:12 1970 +0000
  @@ -1,6 +1,3 @@
  -2
  -2
  -3
   4
   5
   6
  

Add to beginning, trim from end

  $ rm plain
  $ for i in 1 2 3 4 5 6 7 8 9; do
  >  echo $i >> plain
  > done

Record end

  $ hg commit -i --traceback -d '13 0' -m end-again plain<<EOF
  > n
  > y
  > EOF
  diff --git a/plain b/plain
  2 hunks, 4 lines changed
  @@ -1,6 +1,9 @@
  +1
  +2
  +3
   4
   5
   6
   7
   8
   9
684 685
  record change 1/2 to 'plain'?
  (enter ? for help) [Ynesfdaq?] n
686 687 688 689 690 691 692 693 694
  
  @@ -1,7 +4,6 @@
   4
   5
   6
   7
   8
   9
  -10.new
695 696
  record change 2/2 to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
  

Add to beginning, middle, end

  $ rm plain
  $ for i in 1 2 3 4 5 5.new 5.reallynew 6 7 8 9 10 11; do
  >   echo $i >> plain
  > done

Record beginning, middle, and test that format-breaking diffopts are ignored

  $ hg commit -i --config diff.noprefix=True -d '14 0' -m middle-only plain <<EOF
  > y
  > y
  > n
  > EOF
  diff --git a/plain b/plain
  3 hunks, 7 lines changed
  @@ -1,2 +1,5 @@
  +1
  +2
  +3
   4
   5
721 722
  record change 1/3 to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
723 724 725 726 727 728 729 730 731 732
  
  @@ -1,6 +4,8 @@
   4
   5
  +5.new
  +5.reallynew
   6
   7
   8
   9
733 734
  record change 2/3 to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
735 736 737 738 739 740 741 742
  
  @@ -3,4 +8,6 @@
   6
   7
   8
   9
  +10
  +11
743 744
  record change 3/3 to 'plain'?
  (enter ? for help) [Ynesfdaq?] n
745 746 747
  

  $ hg tip -p
748
  changeset:   17:41cf3f5c55ae
749 750 751 752 753
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:14 1970 +0000
  summary:     middle-only
  
754
  diff -r a69d252246e1 -r 41cf3f5c55ae plain
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
  --- a/plain	Thu Jan 01 00:00:13 1970 +0000
  +++ b/plain	Thu Jan 01 00:00:14 1970 +0000
  @@ -1,5 +1,10 @@
  +1
  +2
  +3
   4
   5
  +5.new
  +5.reallynew
   6
   7
   8
  

Record end

  $ hg commit -i -d '15 0' -m end-only plain <<EOF
  > y
  > y
  > EOF
  diff --git a/plain b/plain
  1 hunks, 2 lines changed
timeless's avatar
timeless committed
778
  @@ -9,3 +9,5 @@ 6
779 780 781 782 783
   7
   8
   9
  +10
  +11
784 785
  record this change to 'plain'?
  (enter ? for help) [Ynesfdaq?] y
786 787 788
  

  $ hg tip -p
789
  changeset:   18:58a72f46bc24
790 791 792 793 794
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:15 1970 +0000
  summary:     end-only
  
795
  diff -r 41cf3f5c55ae -r 58a72f46bc24 plain
796 797 798 799 800 801 802 803 804
  --- a/plain	Thu Jan 01 00:00:14 1970 +0000
  +++ b/plain	Thu Jan 01 00:00:15 1970 +0000
  @@ -9,3 +9,5 @@
   7
   8
   9
  +10
  +11
  
805
Interactive commit can name a directory instead of files (issue6131)
806 807

  $ mkdir subdir
808 809 810 811 812
  $ echo a > subdir/a
  $ hg ci -d '16 0' -i subdir -Amsubdir <<EOF
  > y
  > y
  > EOF
813
  adding subdir/a
814 815
  diff --git a/subdir/a b/subdir/a
  new file mode 100644
816 817
  examine changes to 'subdir/a'?
  (enter ? for help) [Ynesfdaq?] y
818 819 820
  
  @@ -0,0 +1,1 @@
  +a
821 822
  record this change to 'subdir/a'?
  (enter ? for help) [Ynesfdaq?] y
823 824
  
  $ cd subdir
825 826 827 828 829 830 831 832 833 834 835

  $ echo a >> a
  $ hg commit -i -d '16 0' -m subdir-change a <<EOF
  > y
  > y
  > EOF
  diff --git a/subdir/a b/subdir/a
  1 hunks, 1 lines changed
  @@ -1,1 +1,2 @@
   a
  +a
836 837
  record this change to 'subdir/a'?
  (enter ? for help) [Ynesfdaq?] y
838 839 840
  

  $ hg tip -p
841
  changeset:   20:e0f6b99f6c49
842 843 844 845 846
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:16 1970 +0000
  summary:     subdir-change
  
847
  diff -r abd26b51de37 -r e0f6b99f6c49 subdir/a
848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
  --- a/subdir/a	Thu Jan 01 00:00:16 1970 +0000
  +++ b/subdir/a	Thu Jan 01 00:00:16 1970 +0000
  @@ -1,1 +1,2 @@
   a
  +a
  

  $ echo a > f1
  $ echo b > f2
  $ hg add f1 f2

  $ hg ci -mz -d '17 0'

  $ echo a >> f1
  $ echo b >> f2

Help, quit

  $ hg commit -i <<EOF
  > ?
  > q
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
872 873
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] ?
874 875 876 877 878 879 880 881 882 883
  
  y - yes, record this change
  n - no, skip this change
  e - edit this change manually
  s - skip remaining changes to this file
  f - record remaining changes to this file
  d - done, skip remaining changes and files
  a - record all changes to all remaining files
  q - quit, recording no changes
  ? - ? (display help)
884 885
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] q
886 887
  
  abort: user quit
888
  [250]
889

890 891 892 893 894 895 896 897 898 899
Patterns

  $ hg commit -i 'glob:f*' << EOF
  > y
  > n
  > y
  > n
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
900 901
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
902 903 904 905
  
  @@ -1,1 +1,2 @@
   a
  +a
906 907
  record change 1/2 to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] n
908 909 910
  
  diff --git a/subdir/f2 b/subdir/f2
  1 hunks, 1 lines changed
911 912
  examine changes to 'subdir/f2'?
  (enter ? for help) [Ynesfdaq?] y
913 914 915 916
  
  @@ -1,1 +1,2 @@
   b
  +b
917 918
  record change 2/2 to 'subdir/f2'?
  (enter ? for help) [Ynesfdaq?] n
919 920 921 922
  
  no changes to record
  [1]

923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
#if gettext

Test translated help message

str.lower() instead of encoding.lower(str) on translated message might
make message meaningless, because some encoding uses 0x41(A) - 0x5a(Z)
as the second or later byte of multi-byte character.

For example, "\x8bL\x98^" (translation of "record" in ja_JP.cp932)
contains 0x4c (L). str.lower() replaces 0x4c(L) by 0x6c(l) and this
replacement makes message meaningless.

This tests that translated help message is lower()-ed correctly.

  $ LANGUAGE=ja
  $ export LANGUAGE

940 941
  $ cat > $TESTTMP/escape.py <<EOF
  > from __future__ import absolute_import
942 943
  > from mercurial import (
  >     pycompat,
944 945 946
  > )
  > from mercurial.utils import (
  >     procutil,
947
  > )
948 949 950 951 952
  > def escape(c):
  >     o = ord(c)
  >     if o < 0x80:
  >         return c
  >     else:
953
  >         return br'\x%02x' % o # escape char setting MSB
954 955 956
  > for l in procutil.stdin:
  >     procutil.stdout.write(
  >         b''.join(escape(c) for c in pycompat.iterbytestr(l)))
957 958
  > EOF

Matt Harbison's avatar
Matt Harbison committed
959
  $ hg commit -i --encoding cp932 2>&1 <<EOF | "$PYTHON" $TESTTMP/escape.py | grep '^y - '
960 961 962
  > ?
  > q
  > EOF
963
  y - \x82\xb1\x82\xcc\x95\xcf\x8dX\x82\xf0\x8bL\x98^(yes)
964 965 966 967

  $ LANGUAGE=
#endif

968 969 970 971 972 973 974
Skip

  $ hg commit -i <<EOF
  > s
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
975 976
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] s
977 978 979
  
  diff --git a/subdir/f2 b/subdir/f2
  1 hunks, 1 lines changed
980 981
  examine changes to 'subdir/f2'?
  (enter ? for help) [Ynesfdaq?] abort: response expected
982 983 984 985 986 987 988 989 990
  [255]

No

  $ hg commit -i <<EOF
  > n
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
991 992
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] n
993 994 995
  
  diff --git a/subdir/f2 b/subdir/f2
  1 hunks, 1 lines changed
996 997
  examine changes to 'subdir/f2'?
  (enter ? for help) [Ynesfdaq?] abort: response expected
998 999 1000 1001 1002 1003 1004 1005 1006 1007
  [255]

f, quit

  $ hg commit -i <<EOF
  > f
  > q
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
1008 1009
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] f
1010 1011 1012
  
  diff --git a/subdir/f2 b/subdir/f2
  1 hunks, 1 lines changed
1013 1014
  examine changes to 'subdir/f2'?
  (enter ? for help) [Ynesfdaq?] q
1015 1016
  
  abort: user quit
1017
  [250]
1018 1019 1020 1021 1022 1023 1024 1025 1026

s, all

  $ hg commit -i -d '18 0' -mx <<EOF
  > s
  > a
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
1027 1028
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] s
1029 1030 1031
  
  diff --git a/subdir/f2 b/subdir/f2
  1 hunks, 1 lines changed
1032 1033
  examine changes to 'subdir/f2'?
  (enter ? for help) [Ynesfdaq?] a
1034 1035 1036
  

  $ hg tip -p
1037
  changeset:   22:6afbbefacf35
1038 1039 1040 1041 1042
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:18 1970 +0000
  summary:     x
  
1043
  diff -r b73c401c693c -r 6afbbefacf35 subdir/f2
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
  --- a/subdir/f2	Thu Jan 01 00:00:17 1970 +0000
  +++ b/subdir/f2	Thu Jan 01 00:00:18 1970 +0000
  @@ -1,1 +1,2 @@
   b
  +b
  

f

  $ hg commit -i -d '19 0' -my <<EOF
  > f
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
1058 1059
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] f
1060 1061 1062
  

  $ hg tip -p
1063
  changeset:   23:715028a33949
1064 1065 1066 1067 1068
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:19 1970 +0000
  summary:     y
  
1069
  diff -r 6afbbefacf35 -r 715028a33949 subdir/f1
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
  --- a/subdir/f1	Thu Jan 01 00:00:18 1970 +0000
  +++ b/subdir/f1	Thu Jan 01 00:00:19 1970 +0000
  @@ -1,1 +1,2 @@
   a
  +a
  

#if execbit

Preserve chmod +x

  $ chmod +x f1
  $ echo a >> f1
  $ hg commit -i -d '20 0' -mz <<EOF
  > y
  > y
  > y
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  old mode 100644
  new mode 100755
  1 hunks, 1 lines changed
1092 1093
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1094 1095 1096 1097 1098
  
  @@ -1,2 +1,3 @@
   a
   a
  +a
1099 1100
  record this change to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1101 1102 1103
  

  $ hg tip --config diff.git=True -p
1104
  changeset:   24:db967c1e5884
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:20 1970 +0000
  summary:     z
  
  diff --git a/subdir/f1 b/subdir/f1
  old mode 100644
  new mode 100755
  --- a/subdir/f1
  +++ b/subdir/f1
  @@ -1,2 +1,3 @@
   a
   a
  +a
  

Preserve execute permission on original

  $ echo b >> f1
  $ hg commit -i -d '21 0' -maa <<EOF
  > y
  > y
  > y
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
1131 1132
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1133 1134 1135 1136 1137 1138
  
  @@ -1,3 +1,4 @@
   a
   a
   a
  +b
1139 1140
  record this change to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1141 1142 1143
  

  $ hg tip --config diff.git=True -p
1144
  changeset:   25:88903aef81c3
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:21 1970 +0000
  summary:     aa
  
  diff --git a/subdir/f1 b/subdir/f1
  --- a/subdir/f1
  +++ b/subdir/f1
  @@ -1,3 +1,4 @@
   a
   a
   a
  +b
  

Preserve chmod -x

  $ chmod -x f1
  $ echo c >> f1
  $ hg commit -i -d '22 0' -mab <<EOF
  > y
  > y
  > y
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  old mode 100755
  new mode 100644
  1 hunks, 1 lines changed
1173 1174
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1175
  
timeless's avatar
timeless committed
1176
  @@ -2,3 +2,4 @@ a
1177 1178 1179 1180
   a
   a
   b
  +c
1181 1182
  record this change to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1183 1184 1185
  

  $ hg tip --config diff.git=True -p
1186
  changeset:   26:7af84b6cf560
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:22 1970 +0000
  summary:     ab
  
  diff --git a/subdir/f1 b/subdir/f1
  old mode 100755
  new mode 100644
  --- a/subdir/f1
  +++ b/subdir/f1
  @@ -2,3 +2,4 @@
   a
   a
   b
  +c
  

#else

Slightly bogus tests to get almost same repo structure as when x bit is used
- but with different hashes.

Mock "Preserve chmod +x"

  $ echo a >> f1
  $ hg commit -i -d '20 0' -mz <<EOF
  > y
  > y
  > y
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
1219 1220
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1221 1222 1223 1224 1225
  
  @@ -1,2 +1,3 @@
   a
   a
  +a
1226 1227
  record this change to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1228 1229 1230
  

  $ hg tip --config diff.git=True -p
1231
  changeset:   24:c26cfe2c4eb0
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:20 1970 +0000
  summary:     z
  
  diff --git a/subdir/f1 b/subdir/f1
  --- a/subdir/f1
  +++ b/subdir/f1
  @@ -1,2 +1,3 @@
   a
   a
  +a
  

Mock "Preserve execute permission on original"

  $ echo b >> f1
  $ hg commit -i -d '21 0' -maa <<EOF
  > y
  > y
  > y
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
1256 1257
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1258 1259 1260 1261 1262 1263
  
  @@ -1,3 +1,4 @@
   a
   a
   a
  +b
1264 1265
  record this change to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1266 1267 1268
  

  $ hg tip --config diff.git=True -p
1269
  changeset:   25:a48d2d60adde
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:21 1970 +0000
  summary:     aa
  
  diff --git a/subdir/f1 b/subdir/f1
  --- a/subdir/f1
  +++ b/subdir/f1
  @@ -1,3 +1,4 @@
   a
   a
   a
  +b
  

Mock "Preserve chmod -x"

  $ chmod -x f1
  $ echo c >> f1
  $ hg commit -i -d '22 0' -mab <<EOF
  > y
  > y
  > y
  > EOF
  diff --git a/subdir/f1 b/subdir/f1
  1 hunks, 1 lines changed
1296 1297
  examine changes to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1298
  
1299
  @@ -2,3 +2,4 @@ a
1300 1301 1302 1303
   a
   a
   b
  +c
1304 1305
  record this change to 'subdir/f1'?
  (enter ? for help) [Ynesfdaq?] y
1306 1307 1308
  

  $ hg tip --config diff.git=True -p
1309
  changeset:   26:5cc89ae210fa
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:22 1970 +0000
  summary:     ab
  
  diff --git a/subdir/f1 b/subdir/f1
  --- a/subdir/f1
  +++ b/subdir/f1
  @@ -2,3 +2,4 @@
   a
   a
   b
  +c
  

#endif

  $ cd ..


Abort early when a merge is in progress

  $ hg up 4
1333
  1 files updated, 0 files merged, 7 files removed, 0 files unresolved
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344

  $ touch iwillmergethat
  $ hg add iwillmergethat

  $ hg branch thatbranch
  marked working directory as branch thatbranch
  (branches are permanent and global, did you want a bookmark?)

  $ hg ci -m'new head'

  $ hg up default
1345
  7 files updated, 0 files merged, 2 files removed, 0 files unresolved
1346 1347 1348 1349 1350 1351 1352

  $ hg merge thatbranch
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  (branch merge, don't forget to commit)

  $ hg commit -i -m'will abort'
  abort: cannot partially commit a merge (use "hg commit" instead)
1353
  [10]
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382

  $ hg up -C
  0 files updated, 0 files merged, 1 files removed, 0 files unresolved

Editing patch (and ignoring trailing text)

  $ cat > editor.sh << '__EOF__'
  > sed -e 7d -e '5s/^-/ /' -e '/^# ---/i\
  > trailing\nditto' "$1" > tmp
  > mv tmp "$1"
  > __EOF__
  $ cat > editedfile << '__EOF__'
  > This is the first line
  > This is the second line
  > This is the third line
  > __EOF__
  $ hg add editedfile
  $ hg commit -medit-patch-1
  $ cat > editedfile << '__EOF__'
  > This line has changed
  > This change will be committed
  > This is the third line
  > __EOF__
  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit -i -d '23 0' -medit-patch-2 <<EOF
  > y
  > e
  > EOF
  diff --git a/editedfile b/editedfile
  1 hunks, 2 lines changed
1383 1384
  examine changes to 'editedfile'?
  (enter ? for help) [Ynesfdaq?] y
1385 1386 1387 1388 1389 1390 1391
  
  @@ -1,3 +1,3 @@
  -This is the first line
  -This is the second line
  +This line has changed
  +This change will be committed
   This is the third line
1392 1393
  record this change to 'editedfile'?
  (enter ? for help) [Ynesfdaq?] e
1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
  
  $ cat editedfile
  This line has changed
  This change will be committed
  This is the third line
  $ hg cat -r tip editedfile
  This is the first line
  This change will be committed
  This is the third line
  $ hg revert editedfile

Trying to edit patch for whole file

  $ echo "This is the fourth line" >> editedfile
  $ hg commit -i <<EOF
  > e
  > q
  > EOF
  diff --git a/editedfile b/editedfile
  1 hunks, 1 lines changed
1414 1415
  examine changes to 'editedfile'?
  (enter ? for help) [Ynesfdaq?] e
1416 1417
  
  cannot edit patch for whole file
1418 1419
  examine changes to 'editedfile'?
  (enter ? for help) [Ynesfdaq?] q
1420 1421
  
  abort: user quit
1422
  [250]
1423