changeset 750:ddbea2fdee5e

evolve: allow updating to the successor if the parent is obsolete Although 'hg update' handles this as well, it will also update to tipmost descendent of the successor, if any.
author Dan Villiom Podlaski Christiansen <dan@cabo.dk>
date Tue, 22 Oct 2013 11:51:01 +0200
parents f728edc7fcd1
children a5474648a9d2
files README hgext/evolve.py tests/test-obsolete.t tests/test-tutorial.t
diffstat 4 files changed, 59 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/README	Wed Jul 31 19:56:28 2013 +0200
+++ b/README	Tue Oct 22 11:51:01 2013 +0200
@@ -49,6 +49,8 @@
 - amend: drop the deprecated note option
 - amend: use core mechanism for amend (fix multiple bugs)
 - parents command: add "working directory parent is obsolete" message
+- evolve command: allow updating to the successor if the parent is
+  obsolete
 
 3.1.0 -- 2013-02-11
 
--- a/hgext/evolve.py	Wed Jul 31 19:56:28 2013 +0200
+++ b/hgext/evolve.py	Tue Oct 22 11:51:01 2013 +0200
@@ -850,6 +850,8 @@
     - rebase unstable changeset to make it stable again,
     - create proper diff from bumped changeset,
     - merge divergent changesets.
+    - update to a successor if the working directory parent is
+      obsolete
 
     By default, take the first trouble changeset that looks relevant.
 
@@ -881,6 +883,40 @@
 
     tr = _picknexttroubled(ui, repo, anyopt or allopt)
     if tr is None:
+        if repo['.'].obsolete():
+            displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
+            successors = set()
+
+            for successorsset in obsolete.successorssets(repo, repo['.'].node()):
+                for nodeid in successorsset:
+                    successors.add(repo[nodeid])
+
+            if not successors:
+                ui.warn(_('parent is obsolete without successors; ' +
+                          'likely killed\n'))
+                return 2
+
+            elif len(successors) > 1:
+                ui.warn(_('parent is obsolete with multiple successors:\n'))
+
+                for ctx in sorted(successors, key=lambda ctx: ctx.rev()):
+                    displayer.show(ctx)
+
+                return 2
+
+            else:
+                ctx = successors.pop()
+
+                ui.status(_('update:'))
+                if not ui.quiet:
+                    displayer.show(ctx)
+
+                if dryrunopt:
+                    print 'hg update %s' % ctx.rev()
+                    return 0
+                else:
+                    return hg.update(repo, ctx.rev())
+
         troubled = repo.revs('troubled()')
         if troubled:
             ui.write_err(_('nothing to evolve here\n'))
--- a/tests/test-obsolete.t	Wed Jul 31 19:56:28 2013 +0200
+++ b/tests/test-obsolete.t	Tue Oct 22 11:51:01 2013 +0200
@@ -663,3 +663,17 @@
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     add obsolet_conflicting_d
   
+
+  $ hg up --hidden 3 -q
+  working directory parent is obsolete!
+  $ hg evolve
+  parent is obsolete with multiple successors:
+  [4] add obsol_c'
+  [10] add obsol_c
+  [2]
+  $ hg olog
+  changeset:   2:4538525df7e2
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add c
+  
--- a/tests/test-tutorial.t	Wed Jul 31 19:56:28 2013 +0200
+++ b/tests/test-tutorial.t	Tue Oct 22 11:51:01 2013 +0200
@@ -673,7 +673,13 @@
   no changes found
   working directory parent is obsolete!
 
-  $ hg up ee942144f952
+now let's see where we are, and update to the successor
+
+  $ hg parents
+  bf1b0d202029 (draft): animals
+  working directory parent is obsolete!
+  $ hg evolve
+  update:[8] animals
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
 Relocating unstable change after prune