changeset 3270:e6150b9b88d9 stable

split: force the branch to fix the split bug Also restore it after the split
author Boris Feld <boris.feld@octobus.net>
date Sun, 10 Dec 2017 21:44:10 +0100
parents e6b980687311
children 21a46dbb0fcb 11a2bc798deb
files hgext3rd/evolve/cmdrewrite.py tests/test-split.t
diffstat 2 files changed, 23 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/evolve/cmdrewrite.py	Sun Dec 10 21:41:56 2017 +0100
+++ b/hgext3rd/evolve/cmdrewrite.py	Sun Dec 10 21:44:10 2017 +0100
@@ -933,6 +933,9 @@
         hnt = _("use either `hg split <rs>` or `hg split --rev <rs>`, not both")
         raise error.Abort(msg, hint=hnt)
 
+    # Save the current branch to restore it in the end
+    savedbranch = repo.dirstate.branch()
+
     try:
         wlock = repo.wlock()
         lock = repo.lock()
@@ -964,6 +967,11 @@
         opts['edit'] = True
         if not opts['user']:
             opts['user'] = ctx.user()
+
+        # Set the right branch
+        # XXX-TODO: Find a way to set the branch without altering the dirstate
+        repo.dirstate.setbranch(ctx.branch())
+
         while haschanges():
             pats = ()
             cmdutil.dorecord(ui, repo, commands.commit, 'commit', False,
@@ -987,6 +995,9 @@
             obsolete.createmarkers(repo, [(repo[rev], newcommits)])
         tr.close()
     finally:
+        # Restore the old branch
+        repo.dirstate.setbranch(savedbranch)
+
         lockmod.release(tr, lock, wlock)
 
 @eh.command(
--- a/tests/test-split.t	Sun Dec 10 21:41:56 2017 +0100
+++ b/tests/test-split.t	Sun Dec 10 21:44:10 2017 +0100
@@ -560,16 +560,16 @@
 
 The splitted changesets should be on the 'another-branch'
   $ hg log -G -l 3
-  @  changeset:   23:4e2e9dee1bcc
-  |  branch:      new-branch
+  @  changeset:   23:56a59faa8af7
+  |  branch:      another-branch
   |  tag:         tip
   |  topic:       mytopic
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     split10
   |
-  o  changeset:   22:8c18390f1ccc
-  |  branch:      new-branch
+  o  changeset:   22:75695e3e2300
+  |  branch:      another-branch
   |  topic:       mytopic
   |  parent:      20:2532b288af61
   |  user:        test
@@ -596,7 +596,7 @@
   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
 
   $ hg log -G -l 2
-  o  changeset:   24:0207fa6107a1
+  o  changeset:   24:b1020d17c364
   |  branch:      yet-another-branch
   |  tag:         tip
   |  topic:       mytopic
@@ -604,15 +604,15 @@
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     To be splitted again
   |
-  @  changeset:   23:4e2e9dee1bcc
-  |  branch:      new-branch
+  @  changeset:   23:56a59faa8af7
+  |  branch:      another-branch
   ~  topic:       mytopic
      user:        test
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     split10
   
   $ hg branch
-  new-branch
+  another-branch
 
   $ hg split -r tip << EOF
   > Y
@@ -633,10 +633,10 @@
   [255]
 
   $ hg branch
-  new-branch
+  another-branch
 
   $ hg log -G -l 2
-  o  changeset:   24:0207fa6107a1
+  o  changeset:   24:b1020d17c364
   |  branch:      yet-another-branch
   |  tag:         tip
   |  topic:       mytopic
@@ -644,8 +644,8 @@
   |  date:        Thu Jan 01 00:00:00 1970 +0000
   |  summary:     To be splitted again
   |
-  @  changeset:   23:4e2e9dee1bcc
-  |  branch:      new-branch
+  @  changeset:   23:56a59faa8af7
+  |  branch:      another-branch
   ~  topic:       mytopic
      user:        test
      date:        Thu Jan 01 00:00:00 1970 +0000