D6355: shelve: add `update --shelve` if shelve extension is loaded

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Thu May 9 07:41:22 EDT 2019


pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  A lot of times, I need to update to some other cset with dirty working
  directory. Good number of times, I run `hg shelve` and `hg update` in order.
  
  Let's add --shelve flag to `hg update` which will shelve wdir changes before
  running the update.
  
  .. feature::
  
    `--shelve` flag to `hg update` if shelve extension is enabled. The flag will
    shelve working directory changes before performing update.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6355

AFFECTED FILES
  hgext/shelve.py
  tests/test-shelve.t

CHANGE DETAILS

diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -1157,3 +1157,22 @@
   [255]
 
   $ cd ..
+
+Test the --shelve flag to `hg update`
+
+  $ hg init sp
+  $ cd sp
+  $ for ch in a b c d; do echo foo>$ch; hg ci -Aqm 'added '$ch; done;
+
+  $ echo babar > a
+  $ hg update '.^' --shelve
+  shelved as default
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg shelve --list
+  default         (1s ago)    changes to: added d
+
+When there is nothing to shelve
+  $ hg update '.^' --shelve
+  nothing changed
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -34,9 +34,11 @@
     bundlerepo,
     changegroup,
     cmdutil,
+    commands,
     discovery,
     error,
     exchange,
+    extensions,
     hg,
     lock as lockmod,
     mdiff,
@@ -1138,7 +1140,22 @@
     else:
         return createcmd(ui, repo, pats, opts)
 
+def _update(orig, ui, repo, *pats, **opts):
+    """ check if --shelve is passed or not. If passed shelves the working
+    directory changes first """
+    if opts[r'shelve']:
+        sopts = {'keep': False, 'message': None, 'interactive': False}
+        createcmd(ui, repo, [], sopts)
+
+    return orig(ui, repo, *pats, **opts)
+
+
 def extsetup(ui):
+    entry = extensions.wrapcommand(commands.table, 'update', _update)
+    options = entry[1]
+    options.append(('', 'shelve', False,
+        _('shelve working directory changes before updating')))
+
     cmdutil.unfinishedstates.append(
         [shelvedstate._filename, False, False,
          _('unshelve already in progress'),



To: pulkit, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list