From d1dd2342aed2fe274f7c9e9cbe893216d81919dc Mon Sep 17 00:00:00 2001 From: Jacob Keller Date: Fri, 7 Dec 2012 13:51:56 -0800 Subject: [PATCH] uncommit: Prevent stack trace for uncommit --to a merge 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 Signed-off-by: Jacob Keller Signed-off-by: Peter P Waskiewicz Jr --- 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) -- 2.11.4.GIT