From da233b16c5b4cb5fdeef476725bee8fa731839f2 Mon Sep 17 00:00:00 2001 From: Nick Hynes Date: Mon, 27 Mar 2017 16:27:37 -0400 Subject: [PATCH] Wrap git_stash_apply --- pygit2/repository.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pygit2/repository.py b/pygit2/repository.py index 17eea0c..6344fb9 100644 --- a/pygit2/repository.py +++ b/pygit2/repository.py @@ -777,6 +777,34 @@ class BaseRepository(_Repository): return Oid(raw=bytes(ffi.buffer(coid)[:])) + def stash_apply(self, index=0, reinstate_index=False, **kwargs): + """Apply a stashed state in the stash list to the working directory. + + :param int index: The position within the stash list of the stash to apply. + 0 is the most recent stash. + :param bool reinstate_index: Try to reinstate stashed changes to the index. + + The checkout options may be customized using the same arguments taken by + Repository.checkout(). + + Example:: + + >>> repo = pygit2.Repsitory('.') + >>> repo.stash(repo.default_signature(), 'WIP: stashing') + >>> repo.stash_apply(strategy=GIT_CHECKOUT_ALLOW_CONFLICTS) + """ + + stash_opts = ffi.new('git_stash_apply_options *') + check_error(C.git_stash_apply_init_options(stash_opts, 1)) + + flags = reinstate_index * C.GIT_STASH_APPLY_REINSTATE_INDEX + stash_opts.flags = flags + + copts, refs = Repository._checkout_args_to_options(**kwargs) + stash_opts.checkout_options = copts[0] + + check_error(C.git_stash_apply(self._repo, index, stash_opts)) + # # Utility for writing a tree into an archive #