diff hgext/shelve.py @ 28571:3f0e25e89e28

shelve: preserve newly created branch on non-bare shelve in wctx (BC) Before this patch current branch in working context wasnt preserved after shelve, this patch makes it restore after update.
author liscju <piotr.listkiewicz@gmail.com>
date Sat, 12 Mar 2016 18:36:31 +0100
parents 2565fe39a76c
children 43c204ddf333
line wrap: on
line diff
--- a/hgext/shelve.py	Fri Mar 18 16:14:57 2016 -0400
+++ b/hgext/shelve.py	Sat Mar 12 18:36:31 2016 +0100
@@ -272,6 +272,7 @@
     if len(parents) > 1:
         raise error.Abort(_('cannot shelve while merging'))
     parent = parents[0]
+    origbranch = wctx.branch()
 
     # we never need the user, so we use a generic user for all shelve operations
     user = 'shelve@localhost'
@@ -378,11 +379,19 @@
             desc = util.ellipsis(desc, ui.termwidth())
         ui.status(_('shelved as %s\n') % name)
         hg.update(repo, parent.node())
+        if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts):
+            repo.dirstate.setbranch(origbranch)
 
         _aborttransaction(repo)
     finally:
         lockmod.release(tr, lock)
 
+def _isbareshelve(pats, opts):
+    return (not pats
+            and not opts.get('interactive', False)
+            and not opts.get('include', False)
+            and not opts.get('exclude', False))
+
 def cleanupcmd(ui, repo):
     """subcommand that deletes all shelves"""