(
callbacks=None,
strategy=None,
directory=None,
paths=None,
c_checkout_options_ptr=None,
)
| 763 | |
| 764 | |
| 765 | def _git_checkout_options( |
| 766 | callbacks=None, |
| 767 | strategy=None, |
| 768 | directory=None, |
| 769 | paths=None, |
| 770 | c_checkout_options_ptr=None, |
| 771 | ): |
| 772 | if callbacks is None: |
| 773 | payload = CheckoutCallbacks() |
| 774 | else: |
| 775 | payload = callbacks |
| 776 | |
| 777 | # Get handle to payload |
| 778 | handle = ffi.new_handle(payload) |
| 779 | |
| 780 | # Create the options struct to pass |
| 781 | if not c_checkout_options_ptr: |
| 782 | opts = ffi.new('git_checkout_options *') |
| 783 | else: |
| 784 | opts = c_checkout_options_ptr |
| 785 | check_error(C.git_checkout_options_init(opts, 1)) |
| 786 | |
| 787 | # References we need to keep to strings and so forth |
| 788 | refs = [handle] |
| 789 | |
| 790 | # pygit2's default is SAFE | RECREATE_MISSING |
| 791 | if strategy is None: |
| 792 | strategy = CheckoutStrategy.SAFE | CheckoutStrategy.RECREATE_MISSING |
| 793 | opts.checkout_strategy = int(strategy) |
| 794 | |
| 795 | if directory: |
| 796 | target_dir = ffi.new('char[]', to_bytes(directory)) |
| 797 | refs.append(target_dir) |
| 798 | opts.target_directory = target_dir |
| 799 | |
| 800 | if paths: |
| 801 | strarray = StrArray(paths) |
| 802 | refs.append(strarray) |
| 803 | opts.paths = strarray.ptr[0] |
| 804 | |
| 805 | # If we want to receive any notifications, set up notify_cb in the options |
| 806 | notify_flags = payload.checkout_notify_flags() |
| 807 | if notify_flags != CheckoutNotify.NONE: |
| 808 | opts.notify_cb = C._checkout_notify_cb |
| 809 | opts.notify_flags = int(notify_flags) |
| 810 | opts.notify_payload = handle |
| 811 | |
| 812 | # Set up progress callback if the user has provided their own |
| 813 | if type(payload).checkout_progress != CheckoutCallbacks.checkout_progress: |
| 814 | opts.progress_cb = C._checkout_progress_cb |
| 815 | opts.progress_payload = handle |
| 816 | |
| 817 | # Give back control |
| 818 | payload.checkout_options = opts |
| 819 | payload._ffi_handle = handle |
| 820 | payload._refs = refs |
| 821 | payload._stored_exception = None |
| 822 | return payload |
no test coverage detected
searching dependent graphs…