diff options
author | Jacob Keller <jacob.e.keller@intel.com> | 2012-12-07 13:51:56 -0800 |
---|---|---|
committer | Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com> | 2013-01-23 09:57:54 -0800 |
commit | d1dd2342aed2fe274f7c9e9cbe893216d81919dc (patch) | |
tree | 48064aa053babaa7619b57a81bb690a363c2face | |
parent | bcb2361ab86abb535ac8d3b07df39c42f03c6c48 (diff) | |
download | stgit-d1dd2342aed2fe274f7c9e9cbe893216d81919dc.tar.gz |
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 <matthew.vick@intel.com>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
-rw-r--r-- | stgit/commands/uncommit.py | 19 |
1 files 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) |