From ac50371bda350d9d8a9d7bd23b1d5691d82b4d0d Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Wed, 8 Nov 2006 22:30:02 +0000 Subject: [PATCH] Add a trash directory with deleted patches Since the delete command now supports multiple patches (and a ".." would remove the whole stack), it is safer to copy the commit ids to .git/patches//trash/ in case a restore is needed. There is no command allowing the restoring yet. Signed-off-by: Catalin Marinas --- stgit/stack.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/stgit/stack.py b/stgit/stack.py index e50f189..2f1a8bc 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -332,6 +332,11 @@ class Series: for patch in self.get_applied() + self.get_unapplied(): self.get_patch(patch).update_top_ref() + # trash directory + self.__trash_dir = os.path.join(self.__series_dir, 'trash') + if self.is_initialised() and not os.path.isdir(self.__trash_dir): + os.makedirs(self.__trash_dir) + def get_branch(self): """Return the branch name for the Series object """ @@ -580,6 +585,11 @@ class Series: for p in patches: Patch(p, self.__patch_dir, self.__refs_dir).delete() + # remove the trash directory + for fname in os.listdir(self.__trash_dir): + os.remove(fname) + os.rmdir(self.__trash_dir) + if os.path.exists(self.__applied_file): os.remove(self.__applied_file) if os.path.exists(self.__unapplied_file): @@ -769,6 +779,9 @@ class Series: elif not name in self.get_unapplied(): raise StackException, 'Unknown patch "%s"' % name + # save the commit id to a trash file + write_string(os.path.join(self.__trash_dir, name), patch.get_top()) + patch.delete() unapplied = self.get_unapplied() -- 2.11.0