shelve: add interactive mode
authorLaurent Charignon <lcharignon@fb.com>
Wed, 25 Mar 2015 15:53:30 -0700
changeset 24478 95cbc77c0cad
parent 24477 325f03de849d
child 24479 871485bd03fd
shelve: add interactive mode This allows us to shelve selectively part of the changes of the workdir
hgext/shelve.py
tests/test-shelve.t
--- a/hgext/shelve.py	Wed Mar 25 15:52:28 2015 -0700
+++ b/hgext/shelve.py	Wed Mar 25 15:53:30 2015 -0700
@@ -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:
--- a/tests/test-shelve.t	Wed Mar 25 15:52:28 2015 -0700
+++ b/tests/test-shelve.t	Wed Mar 25 15:53:30 2015 -0700
@@ -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 ..