diff tests/test-rewind.t @ 4821:d8e36e60aea0

rewind: add --keep flag that "doesn't modify working directory" The actual logic is more complicated than the flag description, but it's sufficiently similar to other --keep flags in action. Unlike strip (or prune), rewind always needs to modify the working directory to commit new revisions that "revive" old ones [1], see _revive_revision() (and rewriteutil.rewrite()). Because of that we don't prevent rewind from modifying wdir, but instead use hg.updaterepo() to update to the old changeset after the "revival" process is complete. Then we rebuild the dirstate based on the commit that rewind would update to without --keep. Since dirstate.rebuild() doesn't restore status of some files (added, removed, also copies and renames), we rely on cmdutil.revert(). It's a fairly crude solution and needs to be removed when implementing the missing copy tracing between oldctx and newctx (which are related only by obsolescence). [1] IOW this means that --keep doesn't allow rewinding if wdir is dirty (unlike e.g. strip).
author Anton Shestakov <av6@dwimlabs.net>
date Thu, 25 Jul 2019 18:37:16 +0800
parents d842a4c6fc4a
children 5cd7d16b8733 c982e7fb5e7a
line wrap: on
line diff
--- a/tests/test-rewind.t	Tue Jul 23 18:05:40 2019 +0800
+++ b/tests/test-rewind.t	Thu Jul 25 18:37:16 2019 +0800
@@ -970,3 +970,83 @@
   ~
 
   $ cd ..
+
+Rewind --keep
+=============
+
+  $ hg init rewind-keep
+  $ cd rewind-keep
+  $ echo root > root
+  $ hg ci -qAm 'root'
+
+  $ echo apple > a
+  $ echo banana > b
+  $ hg ci -qAm initial
+
+  $ hg rm b
+  $ echo apricot > a
+  $ echo coconut > c
+  $ hg add c
+  $ hg status
+  M a
+  A c
+  R b
+  $ hg amend -m amended
+  $ hg glf --hidden
+  @  2: amended (a c)
+  |
+  | x  1: initial (a b)
+  |/
+  o  0: root (root)
+  
+
+Clean wdir
+
+  $ hg rewind --keep --to 'desc("initial")' --hidden
+  rewinded to 1 changesets
+  (1 changesets obsoleted)
+  $ hg obslog
+  @    b4c97fddc16a (3) initial
+  |\
+  x |  2ea5be2f8751 (2) amended
+  |/     rewritten(description, meta, content) as b4c97fddc16a using rewind by test (Thu Jan 01 00:00:06 1970 +0000)
+  |
+  x  30704102d912 (1) initial
+       rewritten(description, content) as 2ea5be2f8751 using amend by test (Thu Jan 01 00:00:06 1970 +0000)
+       rewritten(meta) as b4c97fddc16a using rewind by test (Thu Jan 01 00:00:06 1970 +0000)
+  
+  $ hg glf --hidden
+  @  3: initial (a b)
+  |
+  | x  2: amended (a c)
+  |/
+  | x  1: initial (a b)
+  |/
+  o  0: root (root)
+  
+  $ hg st
+  M a
+  A c
+  R b
+
+Making wdir even more dirty
+
+  $ echo avocado > a
+  $ echo durian > d
+  $ hg st
+  M a
+  A c
+  R b
+  ? d
+
+No rewinding without --keep
+
+  $ hg rewind --to 'desc("amended")' --hidden
+  abort: uncommitted changes
+  [255]
+
+XXX: Unfortunately, even with --keep it's not allowed
+
+  $ hg rewind --keep --to 'desc("amended")' --hidden
+  abort: uncommitted changes
+  [255]