chiark / gitweb /
Add a stack method to delete a patch series
authorChuck Lever <cel@netapp.com>
Thu, 6 Oct 2005 10:12:06 +0000 (11:12 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Thu, 6 Oct 2005 10:12:06 +0000 (11:12 +0100)
In preparation to introducing the ability to delete a branch, add a stack
method that will iterate over a patch series and delete each patch.

Signed-off-by: Chuck Lever <cel@netapp.com>
stgit/stack.py

index 76da21a18e1175a7e13f8bb95fc90feffa233a99..6efee79b032e300dde13bf835a5b7dc0281c516f 100644 (file)
@@ -368,6 +368,32 @@ class Series:
         create_empty_file(self.__unapplied_file)
         self.__begin_stack_check()
 
+    def delete(self, force = False):
+        """Deletes an stgit series
+        """
+        if os.path.isdir(self.__patch_dir):
+            patches = self.get_unapplied() + self.get_applied()
+            if not force and patches:
+                raise StackException, \
+                      'Cannot delete: the series still contains patches'
+            patches.reverse()
+            for p in patches:
+                self.delete_patch(p)
+
+            if os.path.isfile(self.__applied_file):
+                os.remove(self.__applied_file)
+            if os.path.isfile(self.__unapplied_file):
+                os.remove(self.__unapplied_file)
+            if os.path.isfile(self.__current_file):
+                os.remove(self.__current_file)
+            if not os.listdir(self.__patch_dir):
+                os.rmdir(self.__patch_dir)
+            else:
+                print 'Series directory %s is not empty.' % self.__name
+
+        if os.path.isfile(self.__base_file):
+            os.remove(self.__base_file)
+
     def refresh_patch(self, message = None, edit = False, show_patch = False,
                       cache_update = True,
                       author_name = None, author_email = None,