{"thread":{"id":"15227","subject":"[StGit PATCH 1/2] Test that stg coalesce handles head != top gracefully","startedAt":"2008-08-27T22:06:40Z","lastAt":"2008-08-30T22:12:06Z","messageCount":4,"participants":["Karl Hasselström","Catalin Marinas"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"88797","messageId":"20080827220606.3607.17134.stgit@yoghurt","threadId":"15227","inReplyTo":null,"subject":"[StGit PATCH 0/2] Fix bug 12204","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-08-27T22:06:40Z","receivedAt":"2008-08-27T22:06:40Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"This is a test and a fix for https://gna.org/bugs/?12204\n\n---\n\nKarl Hasselström (2):\n      Check for top == head at the start of every transaction\n      Test that stg coalesce handles head != top gracefully\n\n\n stgit/commands/redo.py     |    3 ++-\n stgit/commands/reset.py    |    3 ++-\n stgit/commands/uncommit.py |    3 ++-\n stgit/commands/undo.py     |    3 ++-\n stgit/lib/transaction.py   |   11 ++++++++---\n t/t2600-coalesce.sh        |   13 +++++++++++++\n 6 files changed, 29 insertions(+), 7 deletions(-)\n\n-- \nKarl Hasselström, kha@treskal.com\n      www.treskal.com/kalle\n"},{"id":"88796","messageId":"20080827220649.3607.89509.stgit@yoghurt","threadId":"15227","inReplyTo":"20080827220606.3607.17134.stgit@yoghurt","subject":"[StGit PATCH 1/2] Test that stg coalesce handles head != top gracefully","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-08-27T22:06:49Z","receivedAt":"2008-08-27T22:06:49Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"It currently doesn't quite: it will roll back the transaction just\nfine, but not before asking the user for a commit message which is\nlost in the rollback.\n\nBug discovered by Erik Sandberg <mandolaerik@gmail.com>:\nhttps://gna.org/bugs/?12204\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n t/t2600-coalesce.sh |   13 +++++++++++++\n 1 files changed, 13 insertions(+), 0 deletions(-)\n\n\ndiff --git a/t/t2600-coalesce.sh b/t/t2600-coalesce.sh\nindex ef5bf99..33c073d 100755\n--- a/t/t2600-coalesce.sh\n+++ b/t/t2600-coalesce.sh\n@@ -28,4 +28,17 @@ test_expect_success 'Coalesce at stack top' '\n     [ \"$(echo $(stg series --unapplied --noprefix))\" = \"\" ]\n '\n \n+cat > editor <<EOF\n+#!/bin/sh\n+echo \"Editor was invoked\" | tee editor-invoked\n+EOF\n+chmod a+x editor\n+test_expect_failure 'Coalesce with top != head' '\n+    echo blahonga >> foo.txt &&\n+    git commit -a -m \"a new commit\" &&\n+    EDITOR=./editor command_error stg coalesce --name=r0 p0 q1 &&\n+    test \"$(echo $(stg series))\" = \"+ p0 > q1\" &&\n+    test ! -e editor-invoked\n+'\n+\n test_done\n"},{"id":"88798","messageId":"20080827220657.3607.88972.stgit@yoghurt","threadId":"15227","inReplyTo":"20080827220606.3607.17134.stgit@yoghurt","subject":"[StGit PATCH 2/2] Check for top == head at the start of every transaction","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2008-08-27T22:06:57Z","receivedAt":"2008-08-27T22:06:57Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"We used to check it in the run() method, but that's sometimes too\nlate: for example, it causes stg coalesce to ask for a commit message\n_before_ the check, resulting in a lost commit message if the check\nfails.\n\nAs before, the check can be disabled for the few commands that need\nit.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n\n---\n\n stgit/commands/redo.py     |    3 ++-\n stgit/commands/reset.py    |    3 ++-\n stgit/commands/uncommit.py |    3 ++-\n stgit/commands/undo.py     |    3 ++-\n stgit/lib/transaction.py   |   11 ++++++++---\n t/t2600-coalesce.sh        |    2 +-\n 6 files changed, 17 insertions(+), 8 deletions(-)\n\n\ndiff --git a/stgit/commands/redo.py b/stgit/commands/redo.py\nindex a1075ec..97b7edc 100644\n--- a/stgit/commands/redo.py\n+++ b/stgit/commands/redo.py\n@@ -44,7 +44,8 @@ def func(parser, options, args):\n         raise common.CmdException('Bad number of undos to redo')\n     state = log.undo_state(stack, -options.number)\n     trans = transaction.StackTransaction(stack, 'redo %d' % options.number,\n-                                         discard_changes = options.hard)\n+                                         discard_changes = options.hard,\n+                                         allow_bad_head = True)\n     try:\n         log.reset_stack(trans, stack.repository.default_iw, state)\n     except transaction.TransactionHalted:\ndiff --git a/stgit/commands/reset.py b/stgit/commands/reset.py\nindex 2499b26..d79ce70 100644\n--- a/stgit/commands/reset.py\n+++ b/stgit/commands/reset.py\n@@ -56,7 +56,8 @@ def func(parser, options, args):\n     else:\n         raise common.CmdException('Wrong number of arguments')\n     trans = transaction.StackTransaction(stack, 'reset',\n-                                         discard_changes = options.hard)\n+                                         discard_changes = options.hard,\n+                                         allow_bad_head = True)\n     try:\n         if patches:\n             log.reset_stack_partially(trans, stack.repository.default_iw,\ndiff --git a/stgit/commands/uncommit.py b/stgit/commands/uncommit.py\nindex c21306b..3ffdc1e 100644\n--- a/stgit/commands/uncommit.py\n+++ b/stgit/commands/uncommit.py\n@@ -132,7 +132,8 @@ def func(parser, options, args):\n         patchnames.reverse()\n \n     trans = transaction.StackTransaction(stack, 'uncommit',\n-                                         allow_conflicts = True)\n+                                         allow_conflicts = True,\n+                                         allow_bad_head = True)\n     for commit, pn in zip(commits, patchnames):\n         trans.patches[pn] = commit\n     trans.applied = list(reversed(patchnames)) + trans.applied\ndiff --git a/stgit/commands/undo.py b/stgit/commands/undo.py\nindex 58f1da6..a9cee3a 100644\n--- a/stgit/commands/undo.py\n+++ b/stgit/commands/undo.py\n@@ -41,7 +41,8 @@ def func(parser, options, args):\n         raise common.CmdException('Bad number of commands to undo')\n     state = log.undo_state(stack, options.number)\n     trans = transaction.StackTransaction(stack, 'undo %d' % options.number,\n-                                         discard_changes = options.hard)\n+                                         discard_changes = options.hard,\n+                                         allow_bad_head = True)\n     try:\n         log.reset_stack(trans, stack.repository.default_iw, state)\n     except transaction.TransactionHalted:\ndiff --git a/stgit/lib/transaction.py b/stgit/lib/transaction.py\nindex 7c7139c..c6e2db3 100644\n--- a/stgit/lib/transaction.py\n+++ b/stgit/lib/transaction.py\n@@ -75,7 +75,7 @@ class StackTransaction(object):\n       your refs and index+worktree, or fail without having done\n       anything.\"\"\"\n     def __init__(self, stack, msg, discard_changes = False,\n-                 allow_conflicts = False):\n+                 allow_conflicts = False, allow_bad_head = False):\n         \"\"\"Create a new L{StackTransaction}.\n \n         @param discard_changes: Discard any changes in index+worktree\n@@ -99,6 +99,8 @@ class StackTransaction(object):\n         else:\n             self.__allow_conflicts = allow_conflicts\n         self.__temp_index = self.temp_index_tree = None\n+        if not allow_bad_head:\n+            self.__assert_head_top_equal()\n     stack = property(lambda self: self.__stack)\n     patches = property(lambda self: self.__patches)\n     def __set_applied(self, val):\n@@ -137,13 +139,16 @@ class StackTransaction(object):\n     def __set_head(self, val):\n         self.__bad_head = val\n     head = property(__get_head, __set_head)\n-    def __checkout(self, tree, iw, allow_bad_head):\n-        if not (allow_bad_head or self.__stack.head_top_equal()):\n+    def __assert_head_top_equal(self):\n+        if not self.__stack.head_top_equal():\n             out.error(\n                 'HEAD and top are not the same.',\n                 'This can happen if you modify a branch with git.',\n                 '\"stg repair --help\" explains more about what to do next.')\n             self.__abort()\n+    def __checkout(self, tree, iw, allow_bad_head):\n+        if not allow_bad_head:\n+            self.__assert_head_top_equal()\n         if self.__current_tree == tree and not self.__discard_changes:\n             # No tree change, but we still want to make sure that\n             # there are no unresolved conflicts. Conflicts\ndiff --git a/t/t2600-coalesce.sh b/t/t2600-coalesce.sh\nindex 33c073d..9a043fd 100755\n--- a/t/t2600-coalesce.sh\n+++ b/t/t2600-coalesce.sh\n@@ -33,7 +33,7 @@ cat > editor <<EOF\n echo \"Editor was invoked\" | tee editor-invoked\n EOF\n chmod a+x editor\n-test_expect_failure 'Coalesce with top != head' '\n+test_expect_success 'Coalesce with top != head' '\n     echo blahonga >> foo.txt &&\n     git commit -a -m \"a new commit\" &&\n     EDITOR=./editor command_error stg coalesce --name=r0 p0 q1 &&\n"},{"id":"89270","messageId":"b0943d9e0808301512g6d0a37f7o59e6392687cbafcf@mail.gmail.com","threadId":"15227","inReplyTo":"20080827220657.3607.88972.stgit@yoghurt","subject":"Re: [StGit PATCH 2/2] Check for top == head at the start of every transaction","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2008-08-30T22:12:06Z","receivedAt":"2008-08-30T22:12:06Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"2008/8/27 Karl Hasselström <kha@treskal.com>:\n> We used to check it in the run() method, but that's sometimes too\n> late: for example, it causes stg coalesce to ask for a commit message\n> _before_ the check, resulting in a lost commit message if the check\n> fails.\n>\n> As before, the check can be disabled for the few commands that need\n> it.\n\nLooks fine. Thanks.\n\n-- \nCatalin\n"}]}