From: Jacob Keller <[email protected]>

This patch fixes a bug caused when attempting to stg uncommit --to a merge,
which stgit is not able to handle. Previously stg uncommit would output a nasty
stack trace instead of a clean warning message. This was due to checking for
multiple parents only inside the get_parent function.

The fix is to instead check for parent before appending patch to the list of
patches. Do this by creating a "check_and_append" function which will be called
instead of commits.append(n). The bug was present because of the logic for --to
not calling "get_parent" at the final "to" commit.

Note that the addition of out.done in the exception is to enable slightly better
formatting of the output message (start it on a new line instead of the 
previous one)

Reported-by: Matthew Vick <[email protected]>
Signed-off-by: Jacob Keller <[email protected]>
Signed-off-by: Peter P Waskiewicz Jr <[email protected]>
---
 stgit/commands/uncommit.py | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py
index f303b7f..0dcabff 100644
--- a/stgit/commands/uncommit.py
+++ b/stgit/commands/uncommit.py
@@ -95,23 +95,24 @@ def func(parser, options, args):
         patchnames = args
         patch_nr = len(patchnames)
 
-    def get_parent(c):
-        next = c.data.parents
+    def check_and_append(c, n):
+        next = n.data.parents;
         try:
             [next] = next
         except ValueError:
+            out.done()
             raise common.CmdException(
                 'Trying to uncommit %s, which does not have exactly one parent'
-                % c.sha1)
-        return next
+                % n.sha1)
+        return c.append(n)
 
     commits = []
     next_commit = stack.base
     if patch_nr:
         out.start('Uncommitting %d patches' % patch_nr)
         for i in xrange(patch_nr):
-            commits.append(next_commit)
-            next_commit = get_parent(next_commit)
+            check_and_append(commits, next_commit)
+            next_commit = next_commit.data.parent
     else:
         if options.exclusive:
             out.start('Uncommitting to %s (exclusive)' % to_commit.sha1)
@@ -120,10 +121,10 @@ def func(parser, options, args):
         while True:
             if next_commit == to_commit:
                 if not options.exclusive:
-                    commits.append(next_commit)
+                    check_and_append(commits, next_commit)
                 break
-            commits.append(next_commit)
-            next_commit = get_parent(next_commit)
+            check_and_append(commits, next_commit)
+            next_commit = next_commit.data.parent
         patch_nr = len(commits)
 
     taken_names = set(stack.patchorder.all)
-- 
1.7.11.7


_______________________________________________
stgit-users mailing list
[email protected]
https://mail.gna.org/listinfo/stgit-users

Reply via email to