rewind: update the working copy if it gets obsoleted
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sun, 17 Jun 2018 00:33:43 +0200
changeset 3863 c31be22d1d90
parent 3862 8d3eed113b77
child 3864 0254c96ce108
rewind: update the working copy if it gets obsoleted If the working copy parent is rewinded, follow the rewind.
hgext3rd/evolve/rewind.py
tests/test-rewind.t
--- a/hgext3rd/evolve/rewind.py	Sun Jun 17 01:04:20 2018 +0200
+++ b/hgext3rd/evolve/rewind.py	Sun Jun 17 00:33:43 2018 +0200
@@ -5,6 +5,7 @@
 
 from mercurial import (
     error,
+    hg,
     obsolete,
     obsutil,
     scmutil,
@@ -71,14 +72,23 @@
 
             relationships = []
             cl = unfi.changelog
+            wctxp = repo[None].p1()
+            update_target = None
             for (source, dest) in sorted(successorsmap.items()):
                 newdest = [rewindmap[d] for d in sorted(dest, key=cl.rev)]
                 rel = (unfi[source], tuple(unfi[d] for d in newdest))
                 relationships.append(rel)
+                if wctxp.node() == source:
+                    update_target = newdest[-1]
             obsolete.createmarkers(unfi, relationships, operation='rewind')
+            if update_target is not None:
+                hg.updaterepo(repo, update_target, False)
+
     repo.ui.status(_('rewinded to %d changesets\n') % len(rewinded))
     if relationships:
         repo.ui.status(_('(%d changesets obsoleted)\n') % len(relationships))
+    if update_target is not None:
+        ui.status(_('working directory is now at %s\n') % repo['.'])
 
 def _revive_revision(unfi, rev):
     """rewind a single revision rev.
--- a/tests/test-rewind.t	Sun Jun 17 01:04:20 2018 +0200
+++ b/tests/test-rewind.t	Sun Jun 17 00:33:43 2018 +0200
@@ -363,6 +363,7 @@
   $ hg rewind --hidden --to 'min(desc("c_B0"))'
   rewinded to 1 changesets
   (1 changesets obsoleted)
+  working directory is now at d8b4471cfb3c
   $ hg debugobsolete
   7e594302a05d3769b27be88fc3cdfd39d7498498 25c8f5ab0c3bb569ec672570f1a901be4c6f032b 0 (Thu Jan 01 00:00:01 1970 +0000) {'ef1': '9', 'operation': 'amend', 'user': 'test'}
   7e594302a05d3769b27be88fc3cdfd39d7498498 48acf2c0d9c8961859ce9a913671eb2adc9b057b 4 (Thu Jan 01 00:00:01 1970 +0000) {'ef1': '34', 'operation': 'rewind', 'user': 'test'}
@@ -370,9 +371,9 @@
   7e594302a05d3769b27be88fc3cdfd39d7498498 d8b4471cfb3caa290e0a78ae6bc57d78656c9075 4 (Thu Jan 01 00:00:02 1970 +0000) {'ef1': '34', 'operation': 'rewind', 'user': 'test'}
   25c8f5ab0c3bb569ec672570f1a901be4c6f032b d8b4471cfb3caa290e0a78ae6bc57d78656c9075 0 (Thu Jan 01 00:00:02 1970 +0000) {'ef1': '43', 'operation': 'rewind', 'user': 'test'}
   $ hg obslog --rev 'desc("c_B0")'
-  o    d8b4471cfb3c (5) c_B0
+  @    d8b4471cfb3c (5) c_B0
   |\
-  @ |  25c8f5ab0c3b (3) c_B1
+  x |  25c8f5ab0c3b (3) c_B1
   |/     rewritten(description, meta, date, content) as d8b4471cfb3c using rewind by test (Thu Jan 01 00:00:02 1970 +0000)
   |
   x  7e594302a05d (2) c_B0
@@ -381,20 +382,13 @@
        rewritten(meta, date) as d8b4471cfb3c using rewind by test (Thu Jan 01 00:00:02 1970 +0000)
   
   $ hg log -G
-  o  changeset:   5:d8b4471cfb3c
+  @  changeset:   5:d8b4471cfb3c
   |  tag:         tip
   |  parent:      1:579f120ba918
   |  user:        test
   |  date:        Thu Jan 01 00:00:02 1970 +0000
   |  summary:     c_B0
   |
-  | @  changeset:   3:25c8f5ab0c3b
-  |/   parent:      1:579f120ba918
-  |    user:        test
-  |    date:        Thu Jan 01 00:00:00 1970 +0000
-  |    obsolete:    rewritten using rewind as 5:d8b4471cfb3c
-  |    summary:     c_B1
-  |
   o  changeset:   1:579f120ba918
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
@@ -406,7 +400,7 @@
      summary:     c_ROOT
   
   $ hg log -G --hidden
-  o  changeset:   5:d8b4471cfb3c
+  @  changeset:   5:d8b4471cfb3c
   |  tag:         tip
   |  parent:      1:579f120ba918
   |  user:        test
@@ -420,7 +414,7 @@
   |    obsolete:    pruned using prune
   |    summary:     c_B0
   |
-  | @  changeset:   3:25c8f5ab0c3b
+  | x  changeset:   3:25c8f5ab0c3b
   |/   parent:      1:579f120ba918
   |    user:        test
   |    date:        Thu Jan 01 00:00:00 1970 +0000