evolve: prompt user for branch selection while resolving content-divergence
authorPulkit Goyal <7895pulkit@gmail.com>
Mon, 04 Jun 2018 04:03:02 +0530
changeset 3790 5b9e3aaa6da8
parent 3789 13eef43a961f
child 3791 63d6d024dfb2
evolve: prompt user for branch selection while resolving content-divergence When resolving content-divergence, there can be case when both the content-divergent changesets are on different named branches. In that case, we are not sure which branch should the resolution commit should be on. This patch adds logic to prompt user to choose the branch which the resolution commit should be on and then creates the new resolution commit on that branch. This also adds a new test file which have tests for the branch selection feature we have added.
CHANGELOG
hgext3rd/evolve/evolvecmd.py
tests/test-evolve-content-divergence.t
--- a/CHANGELOG	Tue Jun 05 03:51:01 2018 +0530
+++ b/CHANGELOG	Mon Jun 04 04:03:02 2018 +0530
@@ -1,6 +1,11 @@
 Changelog
 =========
 
+8.1.0 - in progress
+-------------------
+
+  * evolve: handle branch changes when solving content divergence,
+
 8.0.0 -- 2018-04-25
 -------------------
 
--- a/hgext3rd/evolve/evolvecmd.py	Tue Jun 05 03:51:01 2018 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Mon Jun 04 04:03:02 2018 +0530
@@ -456,6 +456,34 @@
         # interrupted evolve
         evolvestate.delete()
 
+        divbranch = divergent.branch()
+        basebranch = base.branch()
+        othbranch = other.branch()
+        # content divergent changes were on different branches, ask user to
+        # select one
+        if divbranch != othbranch:
+
+            if basebranch == othbranch and basebranch != divbranch:
+                # we will be amending the divergent changeset so branch will be
+                # preserved
+                pass
+            elif basebranch == divbranch and basebranch != othbranch:
+                repo.dirstate.setbranch(othbranch)
+            else:
+                # all the three branches are different
+                index = ui.promptchoice(_("content divergent changesets on "
+                                          "different branches.\nchoose branch"
+                                          " for the resolution changeset. (a) "
+                                          "%s or (b) %s or (c) %s? $$ &a $$ &b"
+                                          " $$ &c") %
+                                        (basebranch, divbranch, othbranch), 0)
+            if index == 0:
+                repo.dirstate.setbranch(basebranch)
+            elif index == 1:
+                pass
+            elif index == 2:
+                repo.dirstate.setbranch(othbranch)
+
         # XXX: we should not use amend here, rather create a new commit
         cmdrewrite.amend(ui, repo, message='', logfile='')
         # XXX: we can get rid of this len() call also by creating a new commit
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-evolve-content-divergence.t	Mon Jun 04 04:03:02 2018 +0530
@@ -0,0 +1,84 @@
+** Test for handling of content divergent changesets by `hg evolve` **
+====================================================================
+
+  $ cat >> $HGRCPATH <<EOF
+  > [alias]
+  > glog = log -GT "{rev}:{node|short} {desc|firstline}\n ({bookmarks}) [{branch}] {phase}"
+  > [extensions]
+  > EOF
+  $ echo "evolve=$(echo $(dirname $TESTDIR))/hgext3rd/evolve/" >> $HGRCPATH
+
+  $ hg init cdiv
+  $ cd cdiv
+  $ echo ".*\.orig" > .hgignore
+  $ hg add .hgignore
+  $ hg ci -m "added hgignore"
+  $ for ch in a b c d; do echo foo > $ch; hg add $ch; hg ci -qm "added "$ch; done;
+
+  $ hg glog
+  @  4:c41c793e0ef1 added d
+  |   () [default] draft
+  o  3:ca1b80f7960a added c
+  |   () [default] draft
+  o  2:b1661037fa25 added b
+  |   () [default] draft
+  o  1:c7586e2a9264 added a
+  |   () [default] draft
+  o  0:8fa14d15e168 added hgignore
+      () [default] draft
+
+Creating content-divergence with branch change
+----------------------------------------------
+
+  $ hg branch -r . foobar
+  changed branch on 1 changesets
+
+  $ hg up c41c793e0ef1 --hidden
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  updated to hidden changeset c41c793e0ef1
+  (hidden revision 'c41c793e0ef1' was rewritten as: 9e5dffcb3d48)
+  working directory parent is obsolete! (c41c793e0ef1)
+  (use 'hg evolve' to update to its successor: 9e5dffcb3d48)
+  $ echo bar > d
+  $ hg branch watwat
+  marked working directory as branch watwat
+  $ hg amend
+  2 new content-divergent changesets
+
+  $ hg glog
+  @  6:264b04f771fb added d
+  |   () [watwat] draft
+  | *  5:9e5dffcb3d48 added d
+  |/    () [foobar] draft
+  o  3:ca1b80f7960a added c
+  |   () [default] draft
+  o  2:b1661037fa25 added b
+  |   () [default] draft
+  o  1:c7586e2a9264 added a
+  |   () [default] draft
+  o  0:8fa14d15e168 added hgignore
+      () [default] draft
+
+  $ hg evolve --content-divergent --config ui.interactive=True<<EOF
+  > c
+  > EOF
+  merge:[6] added d
+  with: [5] added d
+  base: [4] added d
+  merging "other" content-divergent changeset '9e5dffcb3d48'
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  content divergent changesets on different branches.
+  choose branch for the resolution changeset. (a) default or (b) watwat or (c) foobar?  c
+  working directory is now at 23a4467c278e
+
+  $ hg glog
+  @  7:23a4467c278e added d
+  |   () [foobar] draft
+  o  3:ca1b80f7960a added c
+  |   () [default] draft
+  o  2:b1661037fa25 added b
+  |   () [default] draft
+  o  1:c7586e2a9264 added a
+  |   () [default] draft
+  o  0:8fa14d15e168 added hgignore
+      () [default] draft