prev: prompt user to choose parent in case of multiple parents
authorPulkit Goyal <7895pulkit@gmail.com>
Fri, 16 Mar 2018 13:13:21 +0530
changeset 3551 ce346c6165c6
parent 3550 78d3ba4e17ac
child 3552 7e8b2c9edf36
prev: prompt user to choose parent in case of multiple parents This patch adds functionality to `hg prev` to prompt user to choose one parent to update when multiple parents exist. Surprisingly there were no tests for this case before this patch, I added one with this patch.
hgext3rd/evolve/__init__.py
tests/test-prev-next.t
--- a/hgext3rd/evolve/__init__.py	Fri Mar 16 12:48:03 2018 +0530
+++ b/hgext3rd/evolve/__init__.py	Fri Mar 16 13:13:21 2018 +0530
@@ -1008,9 +1008,15 @@
         if movebookmark:
             bookmark = repo._activebookmark
     else:
-        for p in parents:
-            displayer.show(p)
-        repo.ui.warn(_('multiple parents, explicitly update to one\n'))
+        header = _("multiple parents, choose one to update:")
+        prevs = [p.rev() for p in parents]
+        choosedrev = utility.revselectionprompt(repo.ui, repo, prevs, header)
+        if choosedrev is None:
+            for p in parents:
+                displayer.show(p)
+            repo.ui.warn(_('multiple parents, explicitly update to one\n'))
+        else:
+            target = repo[choosedrev]
     return target, bookmark
 
 @eh.command(
--- a/tests/test-prev-next.t	Fri Mar 16 12:48:03 2018 +0530
+++ b/tests/test-prev-next.t	Fri Mar 16 13:13:21 2018 +0530
@@ -264,6 +264,64 @@
   atop:[6] added b (3)
   working directory is now at 47ea25be8aea
 
+prev with multiple parents
+
+  $ hg log -GT "{rev}:{node|short} {desc}\n"
+  @  8:47ea25be8aea added d
+  |
+  | o  7:5ce67c2407b0 added c
+  |/
+  o  6:d7f119adc759 added b (3)
+  |
+  o  0:a154386e50d1 added a
+  
+  $ hg merge -r 5ce67c2407b0
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg ci -m "merge commit"
+
+  $ hg prev <<EOF
+  > q
+  > EOF
+  multiple parents, choose one to update:
+  0: [47ea25be8aea] added d
+  1: [5ce67c2407b0] added c
+  q: quit the prompt
+  enter the index of the revision you want to select: q
+  [8] added d
+  [7] added c
+  multiple parents, explicitly update to one
+  [1]
+
+  $ hg prev --config ui.interactive=False
+  [8] added d
+  [7] added c
+  multiple parents, explicitly update to one
+  [1]
+
+  $ hg prev <<EOF
+  > 1
+  > EOF
+  multiple parents, choose one to update:
+  0: [47ea25be8aea] added d
+  1: [5ce67c2407b0] added c
+  q: quit the prompt
+  enter the index of the revision you want to select: 1
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  [7] added c
+
+  $ hg log -GT "{rev}:{node|short} {desc}\n"
+  o    9:a4b8c25a87d3 merge commit
+  |\
+  | o  8:47ea25be8aea added d
+  | |
+  @ |  7:5ce67c2407b0 added c
+  |/
+  o  6:d7f119adc759 added b (3)
+  |
+  o  0:a154386e50d1 added a
+  
+
   $ cd ..
 
 prev and next should lock properly against other commands