1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 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 371 372 373 374 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 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 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 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 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 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 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 636 637 638 639 640 641 642 643 644 645 646 647 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 684 685 686 687 688 689
|
$ cat >> $HGRCPATH <<EOF
> [extensions]
> rebase=
>
> [phases]
> publish=False
>
> [alias]
> tglog = log -G --template "{rev}: '{desc}' {branches}\n"
> EOF
$ hg init a
$ cd a
$ hg unbundle "$TESTDIR/bundles/rebase.hg"
adding changesets
adding manifests
adding file changes
added 8 changesets with 7 changes to 7 files (+2 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)
$ hg up tip
3 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd ..
Rebasing
D onto H - simple rebase:
(this also tests that editor is invoked if '--edit' is specified)
$ hg clone -q -u . a a1
$ cd a1
$ hg tglog
@ 7: 'H'
|
| o 6: 'G'
|/|
o | 5: 'F'
| |
| o 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ hg status --rev "3^1" --rev 3
A D
$ HGEDITOR=cat hg rebase -s 3 -d 7 --edit
D
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: Leave message empty to abort commit.
HG: --
HG: user: Nicolas Dumazet <nicdumz.commits@gmail.com>
HG: branch 'default'
HG: changed D
saved backup bundle to $TESTTMP/a1/.hg/strip-backup/*-backup.hg (glob)
$ hg tglog
o 7: 'D'
|
@ 6: 'H'
|
| o 5: 'G'
|/|
o | 4: 'F'
| |
| o 3: 'E'
|/
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ cd ..
D onto F - intermediate point:
(this also tests that editor is not invoked if '--edit' is not specified)
$ hg clone -q -u . a a2
$ cd a2
$ HGEDITOR=cat hg rebase -s 3 -d 5
saved backup bundle to $TESTTMP/a2/.hg/strip-backup/*-backup.hg (glob)
$ hg tglog
o 7: 'D'
|
| @ 6: 'H'
|/
| o 5: 'G'
|/|
o | 4: 'F'
| |
| o 3: 'E'
|/
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ cd ..
E onto H - skip of G:
$ hg clone -q -u . a a3
$ cd a3
$ hg rebase -s 4 -d 7
saved backup bundle to $TESTTMP/a3/.hg/strip-backup/*-backup.hg (glob)
$ hg tglog
o 6: 'E'
|
@ 5: 'H'
|
o 4: 'F'
|
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ cd ..
F onto E - rebase of a branching point (skip G):
$ hg clone -q -u . a a4
$ cd a4
$ hg rebase -s 5 -d 4
saved backup bundle to $TESTTMP/a4/.hg/strip-backup/*-backup.hg (glob)
$ hg tglog
@ 6: 'H'
|
o 5: 'F'
|
o 4: 'E'
|
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ cd ..
G onto H - merged revision having a parent in ancestors of target:
$ hg clone -q -u . a a5
$ cd a5
$ hg rebase -s 6 -d 7
saved backup bundle to $TESTTMP/a5/.hg/strip-backup/*-backup.hg (glob)
$ hg tglog
o 7: 'G'
|\
| @ 6: 'H'
| |
| o 5: 'F'
| |
o | 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
$ cd ..
F onto B - G maintains E as parent:
$ hg clone -q -u . a a6
$ cd a6
$ hg rebase -s 5 -d 1
saved backup bundle to $TESTTMP/a6/.hg/strip-backup/*-backup.hg (glob)
$ hg tglog
@ 7: 'H'
|
| o 6: 'G'
|/|
o | 5: 'F'
| |
| o 4: 'E'
| |
| | o 3: 'D'
| | |
+---o 2: 'C'
| |
o | 1: 'B'
|/
o 0: 'A'
$ cd ..
These will fail (using --source):
G onto F - rebase onto an ancestor:
$ hg clone -q -u . a a7
$ cd a7
$ hg rebase -s 6 -d 5
nothing to rebase
[1]
F onto G - rebase onto a descendant:
$ hg rebase -s 5 -d 6
abort: source is ancestor of destination
[255]
G onto B - merge revision with both parents not in ancestors of target:
$ hg rebase -s 6 -d 1
abort: cannot use revision 6 as base, result would have 3 parents
[255]
These will abort gracefully (using --base):
G onto G - rebase onto same changeset:
$ hg rebase -b 6 -d 6
nothing to rebase - eea13746799a is both "base" and destination
[1]
G onto F - rebase onto an ancestor:
$ hg rebase -b 6 -d 5
nothing to rebase
[1]
F onto G - rebase onto a descendant:
$ hg rebase -b 5 -d 6
nothing to rebase - "base" 24b6387c8c8c is already an ancestor of destination eea13746799a
[1]
C onto A - rebase onto an ancestor:
$ hg rebase -d 0 -s 2
saved backup bundle to $TESTTMP/a7/.hg/strip-backup/5fddd98957c8-backup.hg (glob)
$ hg tglog
o 7: 'D'
|
o 6: 'C'
|
| @ 5: 'H'
| |
| | o 4: 'G'
| |/|
| o | 3: 'F'
|/ /
| o 2: 'E'
|/
| o 1: 'B'
|/
o 0: 'A'
Check rebasing public changeset
$ hg pull --config phases.publish=True -q -r 6 . # update phase of 6
$ hg rebase -d 0 -b 6
nothing to rebase
[1]
$ hg rebase -d 5 -b 6
abort: can't rebase immutable changeset e1c4361dd923
(see hg help phases for details)
[255]
$ hg rebase -d 5 -b 6 --keep
Check rebasing mutable changeset
Source phase greater or equal to destination phase: new changeset get the phase of source:
$ hg rebase -s9 -d0
saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2b23e52411f4-backup.hg (glob)
$ hg log --template "{phase}\n" -r 9
draft
$ hg rebase -s9 -d1
saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2cb10d0cfc6c-backup.hg (glob)
$ hg log --template "{phase}\n" -r 9
draft
$ hg phase --force --secret 9
$ hg rebase -s9 -d0
saved backup bundle to $TESTTMP/a7/.hg/strip-backup/c5b12b67163a-backup.hg (glob)
$ hg log --template "{phase}\n" -r 9
secret
$ hg rebase -s9 -d1
saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2a0524f868ac-backup.hg (glob)
$ hg log --template "{phase}\n" -r 9
secret
Source phase lower than destination phase: new changeset get the phase of destination:
$ hg rebase -s8 -d9
saved backup bundle to $TESTTMP/a7/.hg/strip-backup/6d4f22462821-backup.hg (glob)
$ hg log --template "{phase}\n" -r 'rev(9)'
secret
$ cd ..
Test for revset
We need a bit different graph
All destination are B
$ hg init ah
$ cd ah
$ hg unbundle "$TESTDIR/bundles/rebase-revset.hg"
adding changesets
adding manifests
adding file changes
added 9 changesets with 9 changes to 9 files (+2 heads)
(run 'hg heads' to see heads, 'hg merge' to merge)
$ hg tglog
o 8: 'I'
|
o 7: 'H'
|
o 6: 'G'
|
| o 5: 'F'
| |
| o 4: 'E'
|/
o 3: 'D'
|
o 2: 'C'
|
| o 1: 'B'
|/
o 0: 'A'
$ cd ..
Simple case with keep:
Source on have two descendant heads but ask for one
$ hg clone -q -u . ah ah1
$ cd ah1
$ hg rebase -r '2::8' -d 1
abort: can't remove original changesets with unrebased descendants
(use --keep to keep original changesets)
[255]
$ hg rebase -r '2::8' -d 1 --keep
$ hg tglog
o 13: 'I'
|
o 12: 'H'
|
o 11: 'G'
|
o 10: 'D'
|
o 9: 'C'
|
| o 8: 'I'
| |
| o 7: 'H'
| |
| o 6: 'G'
| |
| | o 5: 'F'
| | |
| | o 4: 'E'
| |/
| o 3: 'D'
| |
| o 2: 'C'
| |
o | 1: 'B'
|/
o 0: 'A'
$ cd ..
Base on have one descendant heads we ask for but common ancestor have two
$ hg clone -q -u . ah ah2
$ cd ah2
$ hg rebase -r '3::8' -d 1
abort: can't remove original changesets with unrebased descendants
(use --keep to keep original changesets)
[255]
$ hg rebase -r '3::8' -d 1 --keep
$ hg tglog
o 12: 'I'
|
o 11: 'H'
|
o 10: 'G'
|
o 9: 'D'
|
| o 8: 'I'
| |
| o 7: 'H'
| |
| o 6: 'G'
| |
| | o 5: 'F'
| | |
| | o 4: 'E'
| |/
| o 3: 'D'
| |
| o 2: 'C'
| |
o | 1: 'B'
|/
o 0: 'A'
$ cd ..
rebase subset
$ hg clone -q -u . ah ah3
$ cd ah3
$ hg rebase -r '3::7' -d 1
abort: can't remove original changesets with unrebased descendants
(use --keep to keep original changesets)
[255]
$ hg rebase -r '3::7' -d 1 --keep
$ hg tglog
o 11: 'H'
|
o 10: 'G'
|
o 9: 'D'
|
| o 8: 'I'
| |
| o 7: 'H'
| |
| o 6: 'G'
| |
| | o 5: 'F'
| | |
| | o 4: 'E'
| |/
| o 3: 'D'
| |
| o 2: 'C'
| |
o | 1: 'B'
|/
o 0: 'A'
$ cd ..
rebase subset with multiple head
$ hg clone -q -u . ah ah4
$ cd ah4
$ hg rebase -r '3::(7+5)' -d 1
abort: can't remove original changesets with unrebased descendants
(use --keep to keep original changesets)
[255]
$ hg rebase -r '3::(7+5)' -d 1 --keep
$ hg tglog
o 13: 'H'
|
o 12: 'G'
|
| o 11: 'F'
| |
| o 10: 'E'
|/
o 9: 'D'
|
| o 8: 'I'
| |
| o 7: 'H'
| |
| o 6: 'G'
| |
| | o 5: 'F'
| | |
| | o 4: 'E'
| |/
| o 3: 'D'
| |
| o 2: 'C'
| |
o | 1: 'B'
|/
o 0: 'A'
$ cd ..
More advanced tests
rebase on ancestor with revset
$ hg clone -q -u . ah ah5
$ cd ah5
$ hg rebase -r '6::' -d 2
saved backup bundle to $TESTTMP/ah5/.hg/strip-backup/3d8a618087a7-backup.hg (glob)
$ hg tglog
o 8: 'I'
|
o 7: 'H'
|
o 6: 'G'
|
| o 5: 'F'
| |
| o 4: 'E'
| |
| o 3: 'D'
|/
o 2: 'C'
|
| o 1: 'B'
|/
o 0: 'A'
$ cd ..
rebase with multiple root.
We rebase E and G on B
We would expect heads are I, F if it was supported
$ hg clone -q -u . ah ah6
$ cd ah6
$ hg rebase -r '(4+6)::' -d 1
saved backup bundle to $TESTTMP/ah6/.hg/strip-backup/3d8a618087a7-backup.hg (glob)
$ hg tglog
o 8: 'I'
|
o 7: 'H'
|
o 6: 'G'
|
| o 5: 'F'
| |
| o 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
o | 1: 'B'
|/
o 0: 'A'
$ cd ..
More complex rebase with multiple roots
each root have a different common ancestor with the destination and this is a detach
(setup)
$ hg clone -q -u . a a8
$ cd a8
$ echo I > I
$ hg add I
$ hg commit -m I
$ hg up 4
1 files updated, 0 files merged, 3 files removed, 0 files unresolved
$ echo I > J
$ hg add J
$ hg commit -m J
created new head
$ echo I > K
$ hg add K
$ hg commit -m K
$ hg tglog
@ 10: 'K'
|
o 9: 'J'
|
| o 8: 'I'
| |
| o 7: 'H'
| |
+---o 6: 'G'
| |/
| o 5: 'F'
| |
o | 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
(actual test)
$ hg rebase --dest 'desc(G)' --rev 'desc(K) + desc(I)'
saved backup bundle to $TESTTMP/a8/.hg/strip-backup/23a4ace37988-backup.hg (glob)
$ hg log --rev 'children(desc(G))'
changeset: 9:adb617877056
parent: 6:eea13746799a
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: I
changeset: 10:882431a34a0e
tag: tip
parent: 6:eea13746799a
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: K
$ hg tglog
@ 10: 'K'
|
| o 9: 'I'
|/
| o 8: 'J'
| |
| | o 7: 'H'
| | |
o---+ 6: 'G'
|/ /
| o 5: 'F'
| |
o | 4: 'E'
|/
| o 3: 'D'
| |
| o 2: 'C'
| |
| o 1: 'B'
|/
o 0: 'A'
Test that rebase is not confused by $CWD disappearing during rebase (issue 4121)
$ cd ..
$ hg init cwd-vanish
$ cd cwd-vanish
$ touch initial-file
$ hg add initial-file
$ hg commit -m 'initial commit'
$ touch dest-file
$ hg add dest-file
$ hg commit -m 'dest commit'
$ hg up 0
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ touch other-file
$ hg add other-file
$ hg commit -m 'first source commit'
created new head
$ mkdir subdir
$ cd subdir
$ touch subfile
$ hg add subfile
$ hg commit -m 'second source with subdir'
$ hg rebase -b . -d 1 --traceback
saved backup bundle to $TESTTMP/cwd-vanish/.hg/strip-backup/779a07b1b7a0-backup.hg (glob)
|