Don't use test_expect_failure for tests that are supposed to work
[stgit] / stgit / stack.py
index 94856b8..f1f75e4 100644 (file)
@@ -145,7 +145,7 @@ class StgitObject:
         elif os.path.isfile(fname):
             os.remove(fname)
 
-    
+
 class Patch(StgitObject):
     """Basic patch implementation
     """
@@ -165,12 +165,19 @@ class Patch(StgitObject):
         self.create_empty_field('bottom')
         self.create_empty_field('top')
 
-    def delete(self):
-        for f in os.listdir(self._dir()):
-            os.remove(os.path.join(self._dir(), f))
-        os.rmdir(self._dir())
-        git.delete_ref(self.__top_ref)
-        if git.ref_exists(self.__log_ref):
+    def delete(self, keep_log = False):
+        if os.path.isdir(self._dir()):
+            for f in os.listdir(self._dir()):
+                os.remove(os.path.join(self._dir(), f))
+            os.rmdir(self._dir())
+        else:
+            out.warn('Patch directory "%s" does not exist' % self._dir())
+        try:
+            # the reference might not exist if the repository was corrupted
+            git.delete_ref(self.__top_ref)
+        except git.GitException, e:
+            out.warn(str(e))
+        if not keep_log and git.ref_exists(self.__log_ref):
             git.delete_ref(self.__log_ref)
 
     def get_name(self):
@@ -363,10 +370,10 @@ class PatchSet(StgitObject):
 
 
 def shortlog(patches):
-    log = ''.join(Run('git-log', '--pretty=short',
+    log = ''.join(Run('git', 'log', '--pretty=short',
                       p.get_top(), '^%s' % p.get_bottom()).raw_output()
                   for p in patches)
-    return Run('git-shortlog').raw_input(log).raw_output()
+    return Run('git', 'shortlog').raw_input(log).raw_output()
 
 class Series(PatchSet):
     """Class including the operations on series
@@ -746,10 +753,10 @@ class Series(PatchSet):
                 raise StackException('Series directory %s is not empty'
                                      % self._dir())
 
-            try:
-                git.delete_branch(self.get_name())
-            except GitException:
-                out.warn('Could not delete branch "%s"' % self.get_name())
+        try:
+            git.delete_branch(self.get_name())
+        except GitException:
+            out.warn('Could not delete branch "%s"' % self.get_name())
 
         config.remove_section('branch.%s' % self.get_name())
         config.remove_section('branch.%s.stgit' % self.get_name())
@@ -760,7 +767,7 @@ class Series(PatchSet):
                       author_name = None, author_email = None,
                       author_date = None,
                       committer_name = None, committer_email = None,
-                      backup = False, sign_str = None, log = 'refresh',
+                      backup = True, sign_str = None, log = 'refresh',
                       notes = None, bottom = None):
         """Generates a new commit for the topmost patch
         """
@@ -856,7 +863,7 @@ class Series(PatchSet):
         assert not before_existing or (top and bottom)
         assert not (commit and before_existing)
         assert (top and bottom) or (not top and not bottom)
-        assert not top or (bottom == git.get_commit(top).get_parent())
+        assert commit or (not top or (bottom == git.get_commit(top).get_parent()))
 
         if name != None:
             self.__patch_name_valid(name)
@@ -933,7 +940,7 @@ class Series(PatchSet):
 
         return patch
 
-    def delete_patch(self, name):
+    def delete_patch(self, name, keep_log = False):
         """Deletes a patch
         """
         self.__patch_name_valid(name)
@@ -950,7 +957,7 @@ class Series(PatchSet):
         # save the commit id to a trash file
         write_string(os.path.join(self.__trash_dir, name), patch.get_top())
 
-        patch.delete()
+        patch.delete(keep_log = keep_log)
 
         unapplied = self.get_unapplied()
         unapplied.remove(name)
@@ -1167,7 +1174,8 @@ class Series(PatchSet):
         patch = self.get_patch(name)
 
         if git.get_head_file() == self.get_name():
-            if keep and not git.apply_diff(git.get_head(), patch.get_bottom()):
+            if keep and not git.apply_diff(git.get_head(), patch.get_bottom(),
+                                           check_index = False):
                 raise StackException(
                     'Failed to pop patches while preserving the local changes')
             git.switch(patch.get_bottom(), keep)