topic-change: update the working copy along when changing topic of '.'
authorPierre-Yves David <pierre-yves.david@octobus.net>
Wed, 21 Jun 2017 13:18:47 +0200
changeset 2648 d8b47d961c77
parent 2647 b9cfb8bd0965
child 2649 cf930521f14d
topic-change: update the working copy along when changing topic of '.' This avoids leaving the working copy behind, removing another large parts of issue5441.
README
hgext3rd/topic/__init__.py
tests/test-topic.t
--- a/README	Wed Jun 21 13:21:08 2017 +0200
+++ b/README	Wed Jun 21 13:18:47 2017 +0200
@@ -129,7 +129,7 @@
 
  - stack: also show the unstable status for the current changeset (issue5553)
  - stack: properly abort when and unknown topic is requested,
- - topic: fix issue5441 in the linear case,
+ - topic: changing topic on revs no longer adds extra instability (issue5441)
  - topic: topics: rename '--change' flag to '--rev' flag,
 
 6.4.1 - in progress
--- a/hgext3rd/topic/__init__.py	Wed Jun 21 13:21:08 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Wed Jun 21 13:18:47 2017 +0200
@@ -62,6 +62,7 @@
     context,
     error,
     extensions,
+    hg,
     localrepo,
     lock,
     merge,
@@ -306,8 +307,9 @@
 def _changetopics(ui, repo, revset, newtopic):
     rewrote = 0
     needevolve = False
-    l = txn = None
+    wl = l = txn = None
     try:
+        wl = repo.wlock()
         l = repo.lock()
         txn = repo.transaction('rewrite-topics')
         p1 = None
@@ -358,9 +360,19 @@
             needevolve = needevolve or (len(c.children()) > 0)
             obsolete.createmarkers(repo, [(c, (repo[newnode],))])
             rewrote += 1
+        # move the working copy too
+        wctx = repo[None]
+        # in-progress merge is a bit too complexe for now.
+        if len(wctx.parents()) == 1:
+            newid = successors.get(wctx.p1().node())
+            if newid is not None:
+                # this provide some useless output we shoudl eventually suppress
+                #
+                # 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+                hg.update(repo, newid)
         txn.close()
     finally:
-        lock.release(txn, l)
+        lock.release(txn, l, wl)
         repo.invalidate()
     ui.status('changed topic on %d changes\n' % rewrote)
     if needevolve:
--- a/tests/test-topic.t	Wed Jun 21 13:21:08 2017 +0200
+++ b/tests/test-topic.t	Wed Jun 21 13:18:47 2017 +0200
@@ -653,6 +653,8 @@
   
 Reading the same topic with topic --rev should work:
   $ hg topic --rev . watwat
+  switching to topic watwat
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   changed topic on 1 changes
 
 Testing issue5441
@@ -676,10 +678,12 @@
   |
 
   $ hg topics --rev '13::19' changewat
+  switching to topic changewat
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   changed topic on 2 changes
   please run hg evolve --rev "topic(changewat)" now
   $ hg log -Gr 'draft()'
-  o  changeset:   21:58e15a6365ca
+  @  changeset:   21:58e15a6365ca
   |  tag:         tip
   |  topic:       changewat
   |  user:        test
@@ -693,20 +697,6 @@
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     start on fran
   |
-  | @  changeset:   19:b72b86a1f96b
-  | |  topic:       watwat
-  | |  parent:      13:d91cd8fd490e
-  | |  user:        test
-  | |  date:        Thu Jan 01 00:00:00 1970 +0000
-  | |  summary:     fran?
-  | |
-  | x  changeset:   13:d91cd8fd490e
-  |/   topic:       wat
-  |    parent:      3:a53952faf762
-  |    user:        test
-  |    date:        Thu Jan 01 00:00:00 1970 +0000
-  |    summary:     start on fran
-  |
 
 Case with branching:
 
@@ -739,10 +729,12 @@
   |  summary:     start on fran
   |
   $ hg topics --rev 't1::' changewut
+  switching to topic changewut
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   changed topic on 3 changes
   please run hg evolve --rev "topic(changewut)" now
   $ hg log -Gr 'draft()'
-  o  changeset:   25:05d1bf93e1d8
+  @  changeset:   25:05d1bf93e1d8
   |  tag:         tip
   |  topic:       changewut
   |  parent:      23:1f668635e0c2
@@ -763,17 +755,3 @@
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     start on fran
   |
-  | @  changeset:   22:373f490f8854
-  | |  topic:       changewat
-  | |  parent:      20:a96ac830b62e
-  | |  user:        test
-  | |  date:        Thu Jan 01 00:00:00 1970 +0000
-  | |  summary:     gamma
-  | |
-  | x  changeset:   20:a96ac830b62e
-  |/   topic:       changewat
-  |    parent:      3:a53952faf762
-  |    user:        test
-  |    date:        Thu Jan 01 00:00:00 1970 +0000
-  |    summary:     start on fran
-  |