[StGit PATCH 4/6] Make sure that we only uncommit commits with exactly one parent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If we encounter a commit with 0, or 2 or more parents, fail with a
nice error message instead of crashing.

Signed-off-by: Karl Hasselström <kha@xxxxxxxxxxx>

---

 stgit/commands/uncommit.py |   14 ++++++++++++--
 t/t1300-uncommit.sh        |    2 +-
 2 files changed, 13 insertions(+), 3 deletions(-)


diff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py
index 933ec60..272c5db 100644
--- a/stgit/commands/uncommit.py
+++ b/stgit/commands/uncommit.py
@@ -85,13 +85,23 @@ def func(parser, options, args):
         patchnames = args
         patch_nr = len(patchnames)
 
+    def get_parent(c):
+        next = c.data.parents
+        try:
+            [next] = next
+        except ValueError:
+            raise common.CmdException(
+                'Trying to uncommit %s, which does not have exactly one parent'
+                % c.sha1)
+        return next
+
     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 = next_commit.data.parent
+            next_commit = get_parent(next_commit)
     else:
         if options.exclusive:
             out.start('Uncommitting to %s (exclusive)' % to_commit)
@@ -103,7 +113,7 @@ def func(parser, options, args):
                     commits.append(next_commit)
                 break
             commits.append(next_commit)
-            next_commit = next_commit.data.parent
+            next_commit = get_parent(next_commit)
         patch_nr = len(commits)
 
     taken_names = set(stack.patchorder.applied + stack.patchorder.unapplied)
diff --git a/t/t1300-uncommit.sh b/t/t1300-uncommit.sh
index 0d952a7..a906d13 100755
--- a/t/t1300-uncommit.sh
+++ b/t/t1300-uncommit.sh
@@ -78,7 +78,7 @@ test_expect_success \
     stg commit --all
 '
 
-test_expect_failure 'Uncommit a commit with not precisely one parent' '
+test_expect_success 'Uncommit a commit with not precisely one parent' '
     stg uncommit -n 5 ; [ $? = 2 ] &&
     [ "$(echo $(stg series))" = "" ]
 '

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux