Patchwork [3,of,3] shelve: add interactive mode

login
register
mail settings
Submitter Laurent Charignon
Date March 25, 2015, 11:12 p.m.
Message ID <3275882ddb65c92e7fc8.1427325126@dev919.prn2.facebook.com>
Download mbox | patch
Permalink /patch/8273/
State Accepted
Headers show

Comments

Laurent Charignon - March 25, 2015, 11:12 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1427324010 25200
#      Wed Mar 25 15:53:30 2015 -0700
# Node ID 3275882ddb65c92e7fc8c6fd64be08b8e5077199
# Parent  1d83cdf817f4b43ec6e3fb4dd273a97ee6de5fc6
shelve: add interactive mode

This allows us to shelve selectively part of the changes of the workdir
Matt Mackall - March 26, 2015, 10:39 p.m.
On Wed, 2015-03-25 at 16:12 -0700, Laurent Charignon wrote:
> # HG changeset patch
> # User Laurent Charignon <lcharignon@fb.com>
> # Date 1427324010 25200
> #      Wed Mar 25 15:53:30 2015 -0700
> # Node ID 3275882ddb65c92e7fc8c6fd64be08b8e5077199
> # Parent  1d83cdf817f4b43ec6e3fb4dd273a97ee6de5fc6
> shelve: add interactive mode

These are queued for default, thanks.

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -228,8 +228,15 @@ 
             raise util.Abort(_("shelved change names may not start with '.'"))
         interactive = opts.get('interactive', False)
 
-        node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
-
+        def interactivecommitfunc(ui, repo, *pats, **opts):
+            match = scmutil.match(repo['.'], pats, {})
+            message = opts['message']
+            return commitfunc(ui, repo, message, match, opts)
+        if not interactive:
+            node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
+        else:
+            node = cmdutil.dorecord(ui, repo, interactivecommitfunc, 'commit',
+                                    False, cmdutil.recordfilter, *pats, **opts)
         if not node:
             stat = repo.status(match=scmutil.match(repo[None], pats, opts))
             if stat.deleted:
diff --git a/tests/test-shelve.t b/tests/test-shelve.t
--- a/tests/test-shelve.t
+++ b/tests/test-shelve.t
@@ -791,4 +791,76 @@ 
   abort: options '--delete' and '--name' may not be used together
   [255]
 
+Test interactive shelve
+  $ cat <<EOF >> $HGRCPATH
+  > [ui]
+  > interactive = true
+  > EOF
+  $ echo 'a' >> a/b
+  $ cat a/a >> a/b
+  $ echo 'x' >> a/b
+  $ mv a/b a/a
+  $ echo 'a' >> foo/foo
+  $ hg st
+  M a/a
+  ? a/a.orig
+  ? foo/foo
+  $ cat a/a
+  a
+  a
+  c
+  x
+  x
+  $ cat foo/foo
+  foo
+  a
+  $ hg shelve --interactive << EOF
+  > y
+  > y
+  > n
+  > EOF
+  diff --git a/a/a b/a/a
+  2 hunks, 2 lines changed
+  examine changes to 'a/a'? [Ynesfdaq?] y
+  
+  @@ -1,3 +1,4 @@
+  +a
+   a
+   c
+   x
+  record change 1/2 to 'a/a'? [Ynesfdaq?] y
+  
+  @@ -1,3 +2,4 @@
+   a
+   c
+   x
+  +x
+  record change 2/2 to 'a/a'? [Ynesfdaq?] n
+  
+  shelved as test
+  merging a/a
+  0 files updated, 1 files merged, 0 files removed, 0 files unresolved
+  $ cat a/a
+  a
+  c
+  x
+  x
+  $ cat foo/foo
+  foo
+  a
+  $ hg st
+  M a/a
+  ? foo/foo
+  $ hg unshelve
+  unshelving change 'test'
+  temporarily committing pending changes (restore with 'hg unshelve --abort')
+  rebasing shelved changes
+  rebasing 6:65b5d1c34c34 "changes to 'create conflict'" (tip)
+  merging a/a
+  $ cat a/a
+  a
+  a
+  c
+  x
+  x
   $ cd ..