{"thread":{"id":"8045","subject":"[StGIT PATCH] Fix popping on non-active branches","startedAt":"2007-05-08T23:32:46Z","lastAt":"2007-05-08T23:32:46Z","messageCount":1,"participants":["Karl Hasselström"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"41513","messageId":"20070508233133.6417.24979.stgit@yoghurt","threadId":"8045","inReplyTo":null,"subject":"[StGIT PATCH] Fix popping on non-active branches","fromName":"Karl Hasselström","fromEmail":"kha@treskal.com","sentAt":"2007-05-08T23:32:46Z","receivedAt":"2007-05-08T23:32:46Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"Resetting HEAD on the current branch when popping a patch on another\nbranch isn't a great idea.\n\nSigned-off-by: Karl Hasselström <kha@treskal.com>\n---\n\n stgit/git.py   |    8 ++++++--\n stgit/stack.py |   13 +++++++------\n 2 files changed, 13 insertions(+), 8 deletions(-)\n\ndiff --git a/stgit/git.py b/stgit/git.py\nindex d7eb48e..837f927 100644\n--- a/stgit/git.py\n+++ b/stgit/git.py\n@@ -298,14 +298,18 @@ def set_head_file(ref):\n              [os.path.join('refs', 'heads', ref)]) != 0:\n         raise GitException, 'Could not set head to \"%s\"' % ref\n \n+def set_branch(branch, val):\n+    \"\"\"Point branch at a new commit object.\"\"\"\n+    if __run('git-update-ref', [branch, val]) != 0:\n+        raise GitException, 'Could not update %s to \"%s\".' % (branch, val)\n+\n def __set_head(val):\n     \"\"\"Sets the HEAD value\n     \"\"\"\n     global __head\n \n     if not __head or __head != val:\n-        if __run('git-update-ref HEAD', [val]) != 0:\n-            raise GitException, 'Could not update HEAD to \"%s\".' % val\n+        set_branch('HEAD', val)\n         __head = val\n \n     # only allow SHA1 hashes\ndiff --git a/stgit/stack.py b/stgit/stack.py\nindex 3e9fc4f..76704e8 100644\n--- a/stgit/stack.py\n+++ b/stgit/stack.py\n@@ -1063,12 +1063,13 @@ class Series(StgitObject):\n \n         patch = Patch(name, self.__patch_dir, self.__refs_dir)\n \n-        # only keep the local changes\n-        if keep and not git.apply_diff(git.get_head(), patch.get_bottom()):\n-            raise StackException, \\\n-                  'Failed to pop patches while preserving the local changes'\n-\n-        git.switch(patch.get_bottom(), keep)\n+        if git.get_head_file() == self.get_branch():\n+            if keep and not git.apply_diff(git.get_head(), patch.get_bottom()):\n+                raise StackException(\n+                    'Failed to pop patches while preserving the local changes')\n+            git.switch(patch.get_bottom(), keep)\n+        else:\n+            git.set_branch(self.get_branch(), patch.get_bottom())\n \n         # save the new applied list\n         idx = applied.index(name) + 1\n"}]}