libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.58k stars 382 forks source link

Checkout & stash callbacks #1167

Closed jorio closed 1 year ago

jorio commented 1 year ago

This PR exposes libgit2's checkout and stash callbacks to Python code.

This lets you collect information about a checkout/unstash as it's being performed. You can also abort a checkout/unstash prematurely by raising an exception from one of the callbacks.

Sample usage:

class MyCheckoutCallbacks(pygit2.CheckoutCallbacks):
    def checkout_notify(self, why, path, baseline, target, workdir):
        if why == pygit2.GIT_CHECKOUT_NOTIFY_CONFLICT:
            print("Conflict:", path)
        elif why == pygit2.GIT_CHECKOUT_NOTIFY_UPDATED:
            print("Updated:", path)

repo.checkout(some_ref, callbacks=MyCheckoutCallbacks())