X-Git-Url: https://git.distorted.org.uk/~mdw/stgit/blobdiff_plain/4d0ba818236453fae51c9efb64950f23557cc428..b4d6a1c5539886c10f4d3965bd62afc793d8e912:/stgit/stack.py diff --git a/stgit/stack.py b/stgit/stack.py index e50f189..8fa3846 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 """ @@ -412,12 +417,12 @@ class Series: def __patch_is_current(self, patch): return patch.get_name() == read_string(self.__current_file) - def __patch_applied(self, name): + def patch_applied(self, name): """Return true if the patch exists in the applied list """ return name in self.get_applied() - def __patch_unapplied(self, name): + def patch_unapplied(self, name): """Return true if the patch exists in the unapplied list """ return name in self.get_unapplied() @@ -425,7 +430,7 @@ class Series: def patch_exists(self, name): """Return true if there is a patch with the given name, false otherwise.""" - return self.__patch_applied(name) or self.__patch_applied(name) + return self.patch_applied(name) or self.patch_unapplied(name) def __begin_stack_check(self): """Save the current HEAD into .git/refs/heads/base if the stack @@ -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): @@ -703,7 +713,7 @@ class Series: before_existing = False, refresh = True): """Creates a new patch """ - if self.__patch_applied(name) or self.__patch_unapplied(name): + if self.patch_applied(name) or self.patch_unapplied(name): raise StackException, 'Patch "%s" already exists' % name if not message and can_edit: @@ -763,12 +773,15 @@ class Series: if self.__patch_is_current(patch): self.pop_patch(name) - elif self.__patch_applied(name): + elif self.patch_applied(name): raise StackException, 'Cannot remove an applied patch, "%s", ' \ 'which is not current' % name 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()