Patchwork [STABLE] histedit: preserve active branch while histediting

login
register
mail settings
Submitter Boris Feld
Date Dec. 12, 2017, 9:51 p.m.
Message ID <97530db4626d07f40fa7.1513115512@FB>
Download mbox | patch
Permalink /patch/26243/
State Accepted
Headers show

Comments

Boris Feld - Dec. 12, 2017, 9:51 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1513099331 -3600
#      Tue Dec 12 18:22:11 2017 +0100
# Branch stable
# Node ID 97530db4626d07f40fa71c5b28f8557baa867024
# Parent  fdd09d87635b32dbf06563bf1ccaac56798ad882
# EXP-Topic histedit-branch
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 97530db4626d
histedit: preserve active branch while histediting

The branch information was properly preserved in the changeset, but the
"active" branch of the working copy could be lost (the branch of the base
being used).

Histedit used to behave properly in this regard but the case was not tested
and regressed 4 years ago in ab2362e1672e.
Augie Fackler - Dec. 12, 2017, 10:46 p.m.
> On Dec 12, 2017, at 16:51, Boris Feld <boris.feld@octobus.net> wrote:
> 
> # HG changeset patch
> # User Boris Feld <boris.feld@octobus.net>
> # Date 1513099331 -3600
> #      Tue Dec 12 18:22:11 2017 +0100
> # Branch stable
> # Node ID 97530db4626d07f40fa71c5b28f8557baa867024
> # Parent  fdd09d87635b32dbf06563bf1ccaac56798ad882
> # EXP-Topic histedit-branch
> # Available At https://bitbucket.org/octobus/mercurial-devel/
> #              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 97530db4626d
> histedit: preserve active branch while histediting

queued, thanks

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -487,6 +487,7 @@  class histeditaction(object):
         repo.ui.pushbuffer(error=True, labeled=True)
         hg.update(repo, self.state.parentctxnode, quietempty=True)
         stats = applychanges(repo.ui, repo, rulectx, {})
+        repo.dirstate.setbranch(rulectx.branch())
         if stats and stats[3] > 0:
             buf = repo.ui.popbuffer()
             repo.ui.write(*buf)
diff --git a/tests/test-histedit-commute.t b/tests/test-histedit-commute.t
--- a/tests/test-histedit-commute.t
+++ b/tests/test-histedit-commute.t
@@ -454,3 +454,36 @@  Now, let's try to fold the second commit
   rename to another-dir/renamed-file
 
   $ cd ..
+
+Test that branches are preserved and stays active
+-------------------------------------------------
+
+  $ hg init repo-with-branch
+  $ cd repo-with-branch
+  $ echo a > a
+  $ hg add a
+  $ hg commit -m A
+  $ hg branch foo
+  marked working directory as branch foo
+  (branches are permanent and global, did you want a bookmark?)
+  $ echo a > b
+  $ hg add b
+  $ hg commit -m foo-B
+  $ echo a > c
+  $ hg add c
+  $ hg commit -m foo-C
+
+  $ hg branch
+  foo
+  $ echo "pick efefa76d6dc3 2 foo-C" >> cmd
+  $ echo "pick 7336e7550422 1 foo-B" >> cmd
+
+  $ HGEDITOR=cat hg histedit -r ".^" --commands cmd --quiet
+  $ hg log --template '{rev} {branch}\n'
+  2 foo
+  1 foo
+  0 default
+  $ hg branch
+  foo
+
+  $ cd ..