From: Karl Hasselström Date: Thu, 13 Dec 2007 17:10:45 +0000 (+0100) Subject: Expose transaction abort function X-Git-Tag: v0.15-rc1~311 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/59032ccd3656bbbdf53741bab4ccd2dc69356f04 Expose transaction abort function Users of stack transactions may call abort() instead of run(), if they wish to roll back the transaction instead of committing it. Signed-off-by: Karl Hasselström --- diff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py index 77333b3..663d393 100644 --- a/stgit/lib/transaction.py +++ b/stgit/lib/transaction.py @@ -77,6 +77,10 @@ class StackTransaction(object): return self.__patches[self.__applied[-1]] else: return self.__stack.base + def abort(self, iw = None): + # The only state we need to restore is index+worktree. + if iw: + self.__checkout(self.__stack.head.data.tree, iw) def run(self, iw = None): self.__check_consistency() new_head = self.__head @@ -85,9 +89,8 @@ class StackTransaction(object): try: self.__checkout(new_head.data.tree, iw) except git.CheckoutException: - # We have to abort the transaction. The only state we need - # to restore is index+worktree. - self.__checkout(self.__stack.head.data.tree, iw) + # We have to abort the transaction. + self.abort(iw) self.__abort() self.__stack.set_head(new_head, self.__msg)