Checkout the given reference using the given strategy, and update the HEAD. The reference may be a reference name or a Reference object. The default strategy is SAFE | RECREATE_MISSING. If no reference is given, checkout from the index. Parameters:
(
self,
refname: str | None | Reference = None,
**kwargs,
)
| 442 | payload.check_error(err) |
| 443 | |
| 444 | def checkout( |
| 445 | self, |
| 446 | refname: str | None | Reference = None, |
| 447 | **kwargs, |
| 448 | ) -> None: |
| 449 | """ |
| 450 | Checkout the given reference using the given strategy, and update the |
| 451 | HEAD. |
| 452 | The reference may be a reference name or a Reference object. |
| 453 | The default strategy is SAFE | RECREATE_MISSING. |
| 454 | |
| 455 | If no reference is given, checkout from the index. |
| 456 | |
| 457 | Parameters: |
| 458 | |
| 459 | refname : str or Reference |
| 460 | The reference to checkout. After checkout, the current branch will |
| 461 | be switched to this one. |
| 462 | |
| 463 | strategy : CheckoutStrategy |
| 464 | A ``CheckoutStrategy`` value. The default is ``SAFE | RECREATE_MISSING``. |
| 465 | |
| 466 | directory : str |
| 467 | Alternative checkout path to workdir. |
| 468 | |
| 469 | paths : list[str] |
| 470 | A list of files to checkout from the given reference. |
| 471 | If paths is provided, HEAD will not be set to the reference. |
| 472 | |
| 473 | callbacks : CheckoutCallbacks |
| 474 | Optional. Supply a `callbacks` object to get information about |
| 475 | conflicted files, updated files, etc. as the checkout is being |
| 476 | performed. The callbacks can also abort the checkout prematurely. |
| 477 | |
| 478 | The callbacks should be an object which inherits from |
| 479 | `pyclass:CheckoutCallbacks`. It should implement the callbacks |
| 480 | as overridden methods. |
| 481 | |
| 482 | Examples: |
| 483 | |
| 484 | * To checkout from the HEAD, just pass 'HEAD':: |
| 485 | |
| 486 | >>> checkout('HEAD') |
| 487 | |
| 488 | This is identical to calling checkout_head(). |
| 489 | """ |
| 490 | |
| 491 | # Case 1: Checkout index |
| 492 | if refname is None: |
| 493 | return self.checkout_index(**kwargs) |
| 494 | |
| 495 | # Case 2: Checkout head |
| 496 | if refname == 'HEAD': |
| 497 | return self.checkout_head(**kwargs) |
| 498 | |
| 499 | # Case 3: Reference |
| 500 | if isinstance(refname, Reference): |
| 501 | reference = refname |