Add a --set-tree flag to stg push
[stgit] / stgit / lib / transaction.py
index 13323dd..30a153b 100644 (file)
@@ -343,7 +343,13 @@ class StackTransaction(object):
         if any(getattr(cd, a) != getattr(orig_cd, a) for a in
                ['parent', 'tree', 'author', 'message']):
             comm = self.__stack.repository.commit(cd)
-            self.head = comm
+            if merge_conflict:
+                # When we produce a conflict, we'll run the update()
+                # function defined below _after_ having done the
+                # checkout in run(). To make sure that we check out
+                # the real stack top (as it will look after update()
+                # has been run), set it hard here.
+                self.head = comm
         else:
             comm = None
             s = 'unmodified'
@@ -373,6 +379,28 @@ class StackTransaction(object):
             # Update immediately.
             update()
 
+    def push_tree(self, pn):
+        """Push the named patch without updating its tree."""
+        orig_cd = self.patches[pn].data
+        cd = orig_cd.set_committer(None).set_parent(self.top)
+
+        s = ''
+        if any(getattr(cd, a) != getattr(orig_cd, a) for a in
+               ['parent', 'tree', 'author', 'message']):
+            self.patches[pn] = self.__stack.repository.commit(cd)
+        else:
+            s = ' (unmodified)'
+        if cd.is_nochange():
+            s = ' (empty)'
+        out.info('Pushed %s%s' % (pn, s))
+
+        if pn in self.hidden:
+            x = self.hidden
+        else:
+            x = self.unapplied
+        del x[x.index(pn)]
+        self.applied.append(pn)
+
     def reorder_patches(self, applied, unapplied, hidden = None, iw = None):
         """Push and pop patches to attain the given ordering."""
         if hidden is None: