{"thread":{"id":"23812","subject":"[StGit PATCH] Restore the original applied patches during 'commit'","startedAt":"2010-05-15T11:03:05Z","lastAt":"2010-05-15T11:03:05Z","messageCount":1,"participants":["Catalin Marinas"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"141729","messageId":"20100515110305.12922.25133.stgit@toshiba-laptop","threadId":"23812","inReplyTo":null,"subject":"[StGit PATCH] Restore the original applied patches during 'commit'","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2010-05-15T11:03:05Z","receivedAt":"2010-05-15T11:03:05Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"If committing a patch in the middle of a series, the resulting stack\ndoesn't have any patches applied. The trans.pop_patches() function only\nreturns the additional patches that had to be popped rather than all\npopped patches. The patch also adds some tests for the 'commit' command.\n\nSigned-off-by: Catalin Marinas <catalin.marinas@gmail.com>\nReported-by: Jeenu Viswambharan <Jeenu.Viswambharan@arm.com>\nCc: Karl Hasselström <kha@treskal.com>\n---\n stgit/commands/commit.py |    8 ++++++--\n t/t1303-commit.sh        |   21 +++++++++++++++++++++\n 2 files changed, 27 insertions(+), 2 deletions(-)\n\ndiff --git a/stgit/commands/commit.py b/stgit/commands/commit.py\nindex 7bdd8c6..b21c85f 100644\n--- a/stgit/commands/commit.py\n+++ b/stgit/commands/commit.py\n@@ -87,9 +87,13 @@ def func(parser, options, args):\n         for i in xrange(min(len(stack.patchorder.applied), len(patches))):\n             if stack.patchorder.applied[i] == patches[i]:\n                 common_prefix += 1\n+            else:\n+                break\n         if common_prefix < len(patches):\n-            to_push = trans.pop_patches(\n-                lambda pn: pn in stack.patchorder.applied[common_prefix:])\n+            to_push = [pn for pn in stack.patchorder.applied[common_prefix:]\n+                       if pn not in patches[common_prefix:]]\n+            # this pops all the applied patches from common_prefix\n+            trans.pop_patches(lambda pn: pn in to_push)\n             for pn in patches[common_prefix:]:\n                 trans.push_patch(pn, iw)\n         else:\ndiff --git a/t/t1303-commit.sh b/t/t1303-commit.sh\nindex d53b9f2..2d85078 100755\n--- a/t/t1303-commit.sh\n+++ b/t/t1303-commit.sh\n@@ -6,6 +6,27 @@ test_expect_success 'Initialize the StGIT repository' '\n     stg init\n '\n \n+test_expect_success 'Commit middle patch' '\n+    stg new -m p1 &&\n+    stg new -m p2 &&\n+    stg new -m p3 &&\n+    stg new -m p4 &&\n+    stg pop &&\n+    stg commit p2 &&\n+    test \"$(echo $(stg series))\" = \"+ p1 > p3 - p4\"\n+'\n+\n+test_expect_success 'Commit first patch' '\n+    stg commit &&\n+    test \"$(echo $(stg series))\" = \"> p3 - p4\"\n+'\n+\n+test_expect_success 'Commit all patches' '\n+    stg push &&\n+    stg commit -a &&\n+    test \"$(echo $(stg series))\" = \"\"\n+'\n+\n # stg commit with top != head should not succeed, since the committed\n # patches are poptentially lost.\n test_expect_success 'Commit when top != head (should fail)' '\n"}]}