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

login
register
mail settings
Submitter phabricator
Date May 9, 2019, 11:41 a.m.
Message ID <differential-rev-PHID-DREV-ldztcqualuy6plbensfc-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/39991/
State New
Headers show

Comments

phabricator - May 9, 2019, 11:41 a.m.
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




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - May 10, 2019, 4:40 p.m.
martinvonz added inline comments.

INLINE COMMENTS

> test-shelve.t:1177
> +  $ hg update '.^' --shelve
> +  nothing changed
> +  0 files updated, 0 files merged, 1 files removed, 0 files unresolved

It's not clear that this is related to `--shelve`. Can we instead first check if the working is dirty? Or make this message more explicit. The former seems better if you think users (including you) will want to set `defaults.update=--shelve`.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: martinvonz, mercurial-devel
phabricator - May 13, 2019, 1:36 p.m.
mharbison72 added a comment.


  Should this abort if subrepos are present, since you can't shelve a subrepo?  No -S is available on `update`, but maybe looking for .hgsub with any contents is good enough?
  
  I don't have time to play with it right now, but I know updating a dirty repo with dirty subrepos is massively confusing already.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: mharbison72, martinvonz, mercurial-devel
phabricator - May 13, 2019, 6:07 p.m.
mharbison72 added a comment.


  In https://phab.mercurial-scm.org/D6355#92614, @mharbison72 wrote:
  
  > Should this abort if subrepos are present, since you can't shelve a subrepo?  No -S is available on `update`, but maybe looking for .hgsub with any contents is good enough?
  
  
  On second thought, maybe just check for dirty subrepos so that this isn’t completely incompatible with subrepos.

REPOSITORY
  rHG Mercurial

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

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

Patch

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'),