* [StGIT PATCH] Fix popping on non-active branches
@ 2007-05-08 23:32 Karl Hasselström
0 siblings, 0 replies; only message in thread
From: Karl Hasselström @ 2007-05-08 23:32 UTC (permalink / raw)
To: Catalin Marinas; +Cc: git
Resetting HEAD on the current branch when popping a patch on another
branch isn't a great idea.
Signed-off-by: Karl Hasselström <kha@treskal.com>
---
stgit/git.py | 8 ++++++--
stgit/stack.py | 13 +++++++------
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/stgit/git.py b/stgit/git.py
index d7eb48e..837f927 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -298,14 +298,18 @@ def set_head_file(ref):
[os.path.join('refs', 'heads', ref)]) != 0:
raise GitException, 'Could not set head to "%s"' % ref
+def set_branch(branch, val):
+ """Point branch at a new commit object."""
+ if __run('git-update-ref', [branch, val]) != 0:
+ raise GitException, 'Could not update %s to "%s".' % (branch, val)
+
def __set_head(val):
"""Sets the HEAD value
"""
global __head
if not __head or __head != val:
- if __run('git-update-ref HEAD', [val]) != 0:
- raise GitException, 'Could not update HEAD to "%s".' % val
+ set_branch('HEAD', val)
__head = val
# only allow SHA1 hashes
diff --git a/stgit/stack.py b/stgit/stack.py
index 3e9fc4f..76704e8 100644
--- a/stgit/stack.py
+++ b/stgit/stack.py
@@ -1063,12 +1063,13 @@ class Series(StgitObject):
patch = Patch(name, self.__patch_dir, self.__refs_dir)
- # only keep the local changes
- if keep and not git.apply_diff(git.get_head(), patch.get_bottom()):
- raise StackException, \
- 'Failed to pop patches while preserving the local changes'
-
- git.switch(patch.get_bottom(), keep)
+ if git.get_head_file() == self.get_branch():
+ if keep and not git.apply_diff(git.get_head(), patch.get_bottom()):
+ raise StackException(
+ 'Failed to pop patches while preserving the local changes')
+ git.switch(patch.get_bottom(), keep)
+ else:
+ git.set_branch(self.get_branch(), patch.get_bottom())
# save the new applied list
idx = applied.index(name) + 1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2007-05-08 23:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-08 23:32 [StGIT PATCH] Fix popping on non-active branches Karl Hasselström
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).