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@treskal.com>
patchnames = args
patch_nr = len(patchnames)
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)
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)
else:
if options.exclusive:
out.start('Uncommitting to %s (exclusive)' % to_commit)
commits.append(next_commit)
break
commits.append(next_commit)
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)
patch_nr = len(commits)
taken_names = set(stack.patchorder.applied + stack.patchorder.unapplied)
-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))" = "" ]
'
stg uncommit -n 5 ; [ $? = 2 ] &&
[ "$(echo $(stg series))" = "" ]
'