|
1 | 1 | import pathlib
|
| 2 | +import shlex |
2 | 3 | from typing import Any, Literal, Optional, Sequence, Union
|
3 | 4 |
|
4 | 5 | from ..types import StrOrBytesPath, StrOrPath
|
@@ -458,6 +459,199 @@ def fetch(
|
458 | 459 | ["fetch", *local_flags, "--", *required_flags], check_returncode=False
|
459 | 460 | )
|
460 | 461 |
|
| 462 | + def rebase( |
| 463 | + self, |
| 464 | + upstream: Optional[str] = None, |
| 465 | + onto: Optional[str] = None, |
| 466 | + branch: Optional[str] = None, |
| 467 | + apply: Optional[bool] = None, |
| 468 | + merge: Optional[bool] = None, |
| 469 | + quiet: Optional[bool] = None, |
| 470 | + verbose: Optional[bool] = None, |
| 471 | + stat: Optional[bool] = None, |
| 472 | + no_stat: Optional[bool] = None, |
| 473 | + verify: Optional[bool] = None, |
| 474 | + no_verify: Optional[bool] = None, |
| 475 | + fork_point: Optional[bool] = None, |
| 476 | + no_fork_point: Optional[bool] = None, |
| 477 | + whitespace: Optional[str] = None, |
| 478 | + no_whitespace: Optional[bool] = None, |
| 479 | + commit_date_is_author_date: Optional[bool] = None, |
| 480 | + ignore_date: Optional[bool] = None, |
| 481 | + root: Optional[bool] = None, |
| 482 | + autostash: Optional[bool] = None, |
| 483 | + no_autostash: Optional[bool] = None, |
| 484 | + autosquash: Optional[bool] = None, |
| 485 | + no_autosquash: Optional[bool] = None, |
| 486 | + reschedule_failed_exec: Optional[bool] = None, |
| 487 | + no_reschedule_failed_exec: Optional[bool] = None, |
| 488 | + context: Optional[int] = None, |
| 489 | + rerere_autoupdate: Optional[bool] = None, |
| 490 | + no_rerere_autoupdate: Optional[bool] = None, |
| 491 | + keep_empty: Optional[bool] = None, |
| 492 | + no_keep_empty: Optional[bool] = None, |
| 493 | + reapply_cherry_picks: Optional[bool] = None, |
| 494 | + no_reapply_cherry_picks: Optional[bool] = None, |
| 495 | + allow_empty_message: Optional[bool] = None, |
| 496 | + signoff: Optional[bool] = None, |
| 497 | + keep_base: Optional[bool] = None, |
| 498 | + strategy: Optional[Union[str, bool]] = None, |
| 499 | + strategy_option: Optional[str] = None, |
| 500 | + exec: Optional[str] = None, |
| 501 | + gpg_sign: Optional[Union[str, bool]] = None, |
| 502 | + no_gpg_sign: Optional[bool] = None, |
| 503 | + empty: Optional[Union[str, Literal["drop", "keep", "ask"]]] = None, |
| 504 | + rebase_merges: Optional[ |
| 505 | + Union[str, Literal["rebase-cousins", "no-rebase-cousins"]] |
| 506 | + ] = None, |
| 507 | + # |
| 508 | + # Interactive |
| 509 | + # |
| 510 | + interactive: Optional[bool] = None, |
| 511 | + edit_todo: Optional[bool] = None, |
| 512 | + skip: Optional[bool] = None, |
| 513 | + show_current_patch: Optional[bool] = None, |
| 514 | + abort: Optional[bool] = None, |
| 515 | + quit: Optional[bool] = None, |
| 516 | + **kwargs, |
| 517 | + ): |
| 518 | + """Reapply commit on top of another tip. |
| 519 | +
|
| 520 | + Wraps `git rebase <https://git-scm.com/docs/git-rebase>`_. |
| 521 | +
|
| 522 | + Parameters |
| 523 | + ---------- |
| 524 | + continue : bool |
| 525 | + Accepted via kwargs |
| 526 | +
|
| 527 | + Examples |
| 528 | + -------- |
| 529 | + >>> git = Git(dir=git_local_clone.dir) |
| 530 | + >>> git_remote_repo = create_git_remote_repo() |
| 531 | + >>> git.rebase() |
| 532 | + 'Current branch master is up to date.' |
| 533 | + >>> git = Git(dir=git_local_clone.dir) |
| 534 | + >>> git_remote_repo = create_git_remote_repo() |
| 535 | + >>> git.rebase(upstream='origin') |
| 536 | + 'Current branch master is up to date.' |
| 537 | + >>> git.dir.exists() |
| 538 | + True |
| 539 | + """ |
| 540 | + required_flags: list[str] = [] |
| 541 | + local_flags: list[str] = [] |
| 542 | + |
| 543 | + if upstream: |
| 544 | + required_flags.insert(0, upstream) |
| 545 | + if branch: |
| 546 | + required_flags.insert(0, branch) |
| 547 | + if onto: |
| 548 | + local_flags.append(f"--onto {onto}") |
| 549 | + if context: |
| 550 | + local_flags.append(f"--C{context}") |
| 551 | + |
| 552 | + if exec: |
| 553 | + local_flags.append(f"--exec {shlex.quote(exec)}") |
| 554 | + if reschedule_failed_exec: |
| 555 | + local_flags.append("--reschedule-failed-exec") |
| 556 | + if no_reschedule_failed_exec: |
| 557 | + local_flags.append("--no-reschedule-failed-exec") |
| 558 | + if fork_point: |
| 559 | + local_flags.append("--fork-point") |
| 560 | + if no_fork_point: |
| 561 | + local_flags.append("--no-fork-point") |
| 562 | + if root: |
| 563 | + local_flags.append("--root") |
| 564 | + if keep_base: |
| 565 | + local_flags.append("--keep-base") |
| 566 | + if autostash: |
| 567 | + local_flags.append("--autostash") |
| 568 | + if no_autostash: |
| 569 | + local_flags.append("--no-autostash") |
| 570 | + |
| 571 | + if merge: |
| 572 | + local_flags.append("--merge") |
| 573 | + |
| 574 | + if verbose: |
| 575 | + local_flags.append("--verbose") |
| 576 | + if quiet: |
| 577 | + local_flags.append("--quiet") |
| 578 | + if stat: |
| 579 | + local_flags.append("--stat") |
| 580 | + if no_stat: |
| 581 | + local_flags.append("--no-stat") |
| 582 | + |
| 583 | + if whitespace: |
| 584 | + local_flags.append("--whitespace") |
| 585 | + if no_whitespace: |
| 586 | + local_flags.append("--no-whitespace") |
| 587 | + |
| 588 | + if rerere_autoupdate: |
| 589 | + local_flags.append("--rerere-autoupdate") |
| 590 | + if no_rerere_autoupdate: |
| 591 | + local_flags.append("--no-rerwre-autoupdate") |
| 592 | + |
| 593 | + if reapply_cherry_picks: |
| 594 | + local_flags.append("--reapply-cherry-picks") |
| 595 | + if no_reapply_cherry_picks: |
| 596 | + local_flags.append("--no-reapply-cherry-picks") |
| 597 | + |
| 598 | + if keep_empty: |
| 599 | + local_flags.append("--keep-empty") |
| 600 | + if no_keep_empty: |
| 601 | + local_flags.append("--no-keep-empty") |
| 602 | + |
| 603 | + if verify: |
| 604 | + local_flags.append("--verify") |
| 605 | + if no_verify: |
| 606 | + local_flags.append("--no-verify") |
| 607 | + |
| 608 | + if ignore_date: |
| 609 | + local_flags.append("--ignore-date") |
| 610 | + if commit_date_is_author_date: |
| 611 | + local_flags.append("--commit-date-is-author-date") |
| 612 | + |
| 613 | + if empty is not None: |
| 614 | + if isinstance(empty, str): |
| 615 | + local_flags.append(f"--empty={empty}") |
| 616 | + else: |
| 617 | + local_flags.append("--empty") |
| 618 | + |
| 619 | + if rebase_merges is not None: |
| 620 | + if isinstance(rebase_merges, str): |
| 621 | + local_flags.append(f"--rebase-merges={rebase_merges}") |
| 622 | + else: |
| 623 | + local_flags.append("--rebase-merges") |
| 624 | + |
| 625 | + if gpg_sign is not None: |
| 626 | + if isinstance(gpg_sign, str): |
| 627 | + local_flags.append(f"--gpg-sign={gpg_sign}") |
| 628 | + else: |
| 629 | + local_flags.append("--gpg-sign") |
| 630 | + if no_gpg_sign: |
| 631 | + local_flags.append("--no-gpg-sign") |
| 632 | + if signoff: |
| 633 | + local_flags.append("--signoff") |
| 634 | + |
| 635 | + # |
| 636 | + # Interactive |
| 637 | + # |
| 638 | + if interactive: |
| 639 | + local_flags.append("--interactive") |
| 640 | + if kwargs.get("continue"): |
| 641 | + local_flags.append("--continue") |
| 642 | + if abort: |
| 643 | + local_flags.append("--abort") |
| 644 | + if edit_todo: |
| 645 | + local_flags.append("--edit-todo") |
| 646 | + if show_current_patch: |
| 647 | + local_flags.append("--show-current-patch") |
| 648 | + if quit: |
| 649 | + local_flags.append("--quit") |
| 650 | + |
| 651 | + return self.run( |
| 652 | + ["rebase", *local_flags, *required_flags], check_returncode=False |
| 653 | + ) |
| 654 | + |
461 | 655 | def pull(
|
462 | 656 | self,
|
463 | 657 | reftag: Optional[Any] = None,
|
|
0 commit comments