[PATCH 1 of 3 V5] shelve: preserve newly created branch on non-bare shelve in wctx (BC)

liscju piotr.listkiewicz at gmail.com
Sat Mar 12 23:32:53 UTC 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1457804191 -3600
#      Sat Mar 12 18:36:31 2016 +0100
# Node ID 7ad2bc86e9efef062162649bf2747fd8533b81ed
# Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
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.

diff -r a036e1ae1fbe -r 7ad2bc86e9ef hgext/shelve.py
--- a/hgext/shelve.py	Sun Feb 07 00:49:31 2016 -0600
+++ b/hgext/shelve.py	Sat Mar 12 18:36:31 2016 +0100
@@ -251,6 +251,7 @@ def _docreatecmd(ui, repo, pats, opts):
     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 at localhost'
@@ -357,11 +358,19 @@ def _docreatecmd(ui, repo, pats, opts):
             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"""
 
diff -r a036e1ae1fbe -r 7ad2bc86e9ef tests/test-shelve.t
--- a/tests/test-shelve.t	Sun Feb 07 00:49:31 2016 -0600
+++ b/tests/test-shelve.t	Sat Mar 12 18:36:31 2016 +0100
@@ -1314,3 +1314,62 @@ And if I shelve, commit, then unshelve, 
   $ hg commit -qm "Remove unknown"
 
   $ cd ..
+
+We expects that non-bare shelve keeps newly created branch in
+working directory.
+
+  $ hg init shelve-preserve-new-branch
+  $ cd shelve-preserve-new-branch
+  $ echo "a" >> a
+  $ hg add a
+  $ echo "b" >> b
+  $ hg add b
+  $ hg commit -m "ab"
+  $ echo "aa" >> a
+  $ echo "bb" >> b
+  $ hg branch new-branch
+  marked working directory as branch new-branch
+  (branches are permanent and global, did you want a bookmark?)
+  $ hg status
+  M a
+  M b
+  $ hg branch
+  new-branch
+  $ hg shelve a
+  shelved as default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg branch
+  new-branch
+  $ hg status
+  M b
+  $ touch "c" >> c
+  $ hg add c
+  $ hg status
+  M b
+  A c
+  $ hg shelve --exclude c
+  shelved as default-01
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg branch
+  new-branch
+  $ hg status
+  A c
+  $ hg shelve --include c
+  shelved as default-02
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg branch
+  new-branch
+  $ hg status
+  $ echo "d" >> d
+  $ hg add d
+  $ hg status
+  A d
+
+We expect that bare-shelve will not keep branch in current working directory.
+
+  $ hg shelve
+  shelved as default-03
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg branch
+  default
+


More information about the Mercurial-devel mailing list