Fix bug 12204
cover Fix bug 12204
This is a test and a fix for https://gna.org/bugs/?12204
---
Karl Hasselström (2):
Check for top == head at the start of every transaction
Test that stg coalesce handles head != top gracefullystgit/commands/redo.py | 3 ++- stgit/commands/reset.py | 3 ++- stgit/commands/uncommit.py | 3 ++- stgit/commands/undo.py | 3 ++- stgit/lib/transaction.py | 11 ++++++++--- t/t2600-coalesce.sh | 13 +++++++++++++ 6 files changed, 29 insertions(+), 7 deletions(-)
Signature · 2 lines
Karl Hasselström, [email protected] www.treskal.com/kalle
PATCH 1/2 Test that stg coalesce handles head != top gracefully
It currently doesn't quite: it will roll back the transaction just fine, but not before asking the user for a commit message which is lost in the rollback.
Bug discovered by Erik Sandberg <[email protected]>:
https://gna.org/bugs/?12204
---
t/t2600-coalesce.sh | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
t/t2600-coalesce.sh +13 -0
@@ -28,4 +28,17 @@ test_expect_success 'Coalesce at stack top' ' [ "$(echo $(stg series --unapplied --noprefix))" = "" ] ' +cat > editor <<EOF +#!/bin/sh +echo "Editor was invoked" | tee editor-invoked +EOF +chmod a+x editor +test_expect_failure 'Coalesce with top != head' ' + echo blahonga >> foo.txt && + git commit -a -m "a new commit" && + EDITOR=./editor command_error stg coalesce --name=r0 p0 q1 && + test "$(echo $(stg series))" = "+ p0 > q1" && + test ! -e editor-invoked +' + test_done
PATCH 2/2 Check for top == head at the start of every transaction
In reply to Karl HasselströmWe used to check it in the run() method, but that's sometimes too
late: for example, it causes stg coalesce to ask for a commit message _before_ the check, resulting in a lost commit message if the check fails.
As before, the check can be disabled for the few commands that need it.
---
stgit/commands/redo.py | 3 ++- stgit/commands/reset.py | 3 ++- stgit/commands/uncommit.py | 3 ++- stgit/commands/undo.py | 3 ++- stgit/lib/transaction.py | 11 ++++++++--- t/t2600-coalesce.sh | 2 +- 6 files changed, 17 insertions(+), 8 deletions(-)
stgit/commands/redo.py +2 -1
@@ -44,7 +44,8 @@ def func(parser, options, args): raise common.CmdException('Bad number of undos to redo') state = log.undo_state(stack, -options.number) trans = transaction.StackTransaction(stack, 'redo %d' % options.number, - discard_changes = options.hard) + discard_changes = options.hard, + allow_bad_head = True) try: log.reset_stack(trans, stack.repository.default_iw, state) except transaction.TransactionHalted:
stgit/commands/reset.py +2 -1
@@ -56,7 +56,8 @@ def func(parser, options, args): else: raise common.CmdException('Wrong number of arguments') trans = transaction.StackTransaction(stack, 'reset', - discard_changes = options.hard) + discard_changes = options.hard, + allow_bad_head = True) try: if patches: log.reset_stack_partially(trans, stack.repository.default_iw,
stgit/commands/uncommit.py +2 -1
@@ -132,7 +132,8 @@ def func(parser, options, args): patchnames.reverse() trans = transaction.StackTransaction(stack, 'uncommit', - allow_conflicts = True) + allow_conflicts = True, + allow_bad_head = True) for commit, pn in zip(commits, patchnames): trans.patches[pn] = commit trans.applied = list(reversed(patchnames)) + trans.applied
stgit/commands/undo.py +2 -1
@@ -41,7 +41,8 @@ def func(parser, options, args): raise common.CmdException('Bad number of commands to undo') state = log.undo_state(stack, options.number) trans = transaction.StackTransaction(stack, 'undo %d' % options.number, - discard_changes = options.hard) + discard_changes = options.hard, + allow_bad_head = True) try: log.reset_stack(trans, stack.repository.default_iw, state) except transaction.TransactionHalted:
stgit/lib/transaction.py +8 -3
@@ -75,7 +75,7 @@ class StackTransaction(object): your refs and index+worktree, or fail without having done anything.""" def __init__(self, stack, msg, discard_changes = False, - allow_conflicts = False): + allow_conflicts = False, allow_bad_head = False): """Create a new L{StackTransaction}. @param discard_changes: Discard any changes in index+worktree
@@ -99,6 +99,8 @@ class StackTransaction(object): else: self.__allow_conflicts = allow_conflicts self.__temp_index = self.temp_index_tree = None + if not allow_bad_head: + self.__assert_head_top_equal() stack = property(lambda self: self.__stack) patches = property(lambda self: self.__patches) def __set_applied(self, val):
@@ -137,13 +139,16 @@ class StackTransaction(object): def __set_head(self, val): self.__bad_head = val head = property(__get_head, __set_head) - def __checkout(self, tree, iw, allow_bad_head): - if not (allow_bad_head or self.__stack.head_top_equal()): + def __assert_head_top_equal(self): + if not self.__stack.head_top_equal(): out.error( 'HEAD and top are not the same.', 'This can happen if you modify a branch with git.', '"stg repair --help" explains more about what to do next.') self.__abort() + def __checkout(self, tree, iw, allow_bad_head): + if not allow_bad_head: + self.__assert_head_top_equal() if self.__current_tree == tree and not self.__discard_changes: # No tree change, but we still want to make sure that # there are no unresolved conflicts. Conflicts
t/t2600-coalesce.sh +1 -1
@@ -33,7 +33,7 @@ cat > editor <<EOF echo "Editor was invoked" | tee editor-invoked EOF chmod a+x editor -test_expect_failure 'Coalesce with top != head' ' +test_expect_success 'Coalesce with top != head' ' echo blahonga >> foo.txt && git commit -a -m "a new commit" && EDITOR=./editor command_error stg coalesce --name=r0 p0 q1 &&
Re: [StGit PATCH 2/2] Check for top == head at the start of every transaction
2008/8/27 Karl Hasselström <[email protected]>:
Quoted 7 lines
We used to check it in the
run()method, but that's sometimes too
late: for example, it causes stg coalesce to ask for a commit message _before_ the check, resulting in a lost commit message if the check fails.As before, the check can be disabled for the few commands that need it.
Looks fine. Thanks.
Signature · 1 line
Catalin