evolve: adds a --confirm option
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 08 Aug 2014 23:02:26 -0700
changeset 1047 d830377bf186
parent 1046 296d48e1f55a
child 1048 a585353a816b
child 1051 d2fe19c818ea
evolve: adds a --confirm option This option lets the use double check if it wants the evolve operation.
README
hgext/evolve.py
tests/test-stabilize-result.t
--- a/README	Fri Aug 08 23:11:09 2014 -0700
+++ b/README	Fri Aug 08 23:02:26 2014 -0700
@@ -62,6 +62,7 @@
 - amend: add -D/--current-date option
 - amend: add -U/--current-user option
 - evolve: add a --tool option
+- evolve: add a --confirm option
 - mark "commit -o", "graft -o" and "graft -O" as deprecated since they are
   unlikely to eventually make it into core.
 - push obsmarkers and phases in the same transaction than changesets
--- a/hgext/evolve.py	Fri Aug 08 23:11:09 2014 -0700
+++ b/hgext/evolve.py	Fri Aug 08 23:02:26 2014 -0700
@@ -1151,6 +1151,8 @@
 @command('^evolve|stabilize|solve',
     [('n', 'dry-run', False,
         'do not perform actions, just print what would be done'),
+     ('', 'confirm', False,
+        'ask for confirmation before performing the action'),
     ('A', 'any', False, 'also consider troubled changesets unrelated to current working directory'),
     ('a', 'all', False, 'evolve all troubled changesets in the repo '
                         '(implies any)'),
@@ -1186,6 +1188,7 @@
     anyopt = opts['any']
     allopt = opts['all']
     dryrunopt = opts['dry_run']
+    confirmopt = opts['confirm']
     ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'evolve')
 
     if contopt:
@@ -1256,7 +1259,7 @@
             wlock = repo.wlock()
             lock = repo.lock()
             tr = repo.transaction("evolve")
-            result = _evolveany(ui, repo, tro, dryrunopt,
+            result = _evolveany(ui, repo, tro, dryrunopt, confirmopt,
                                 progresscb=progresscb)
             tr.close()
         finally:
@@ -1272,19 +1275,20 @@
         ui.progress('evolve', None)
 
 
-def _evolveany(ui, repo, tro, dryrunopt, progresscb):
+def _evolveany(ui, repo, tro, dryrunopt, confirmopt, progresscb):
     repo = repo.unfiltered()
     tro = repo[tro.rev()]
     cmdutil.bailifchanged(repo)
     troubles = tro.troubles()
     if 'unstable' in troubles:
-        return _solveunstable(ui, repo, tro, dryrunopt, progresscb)
+        return _solveunstable(ui, repo, tro, dryrunopt, confirmopt, progresscb)
     elif 'bumped' in troubles:
-        return _solvebumped(ui, repo, tro, dryrunopt, progresscb)
+        return _solvebumped(ui, repo, tro, dryrunopt, confirmopt, progresscb)
     elif 'divergent' in troubles:
         repo = repo.unfiltered()
         tro = repo[tro.rev()]
-        return _solvedivergent(ui, repo, tro, dryrunopt, progresscb)
+        return _solvedivergent(ui, repo, tro, dryrunopt, confirmopt,
+                               progresscb)
     else:
         assert False  # WHAT? unknown troubles
 
@@ -1337,7 +1341,8 @@
                 return child
     return None
 
-def _solveunstable(ui, repo, orig, dryrun=False, progresscb=None):
+def _solveunstable(ui, repo, orig, dryrun=False, confirm=False,
+                   progresscb=None):
     """Stabilize a unstable changeset"""
     obs = orig.parents()[0]
     if not obs.obsolete():
@@ -1362,11 +1367,13 @@
     target = targets[0]
     displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
     target = repo[target]
-    if not ui.quiet:
+    if not ui.quiet or confirm:
         repo.ui.write(_('move:'))
         displayer.show(orig)
         repo.ui.write(_('atop:'))
         displayer.show(target)
+    if confirm and ui.prompt('perform evolve? [Ny]') != 'y':
+            raise util.Abort(_('evolve aborted by user'))
     if progresscb: progresscb()
     todo = 'hg rebase -r %s -d %s\n' % (orig, target)
     if dryrun:
@@ -1383,7 +1390,8 @@
                 _('fix conflict and run "hg evolve --continue"\n'))
             raise
 
-def _solvebumped(ui, repo, bumped, dryrun=False, progresscb=None):
+def _solvebumped(ui, repo, bumped, dryrun=False, confirm=False,
+                 progresscb=None):
     """Stabilize a bumped changeset"""
     # For now we deny bumped merge
     if len(bumped.parents()) > 1:
@@ -1396,11 +1404,13 @@
                          ' %s being a merge' % prec)
 
     displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
-    if not ui.quiet:
+    if not ui.quiet or confirm:
         repo.ui.write(_('recreate:'))
         displayer.show(bumped)
         repo.ui.write(_('atop:'))
         displayer.show(prec)
+    if confirm and ui.prompt('perform evolve? [Ny]') != 'y':
+        raise util.Abort(_('evolve aborted by user'))
     if dryrun:
         todo = 'hg rebase --rev %s --dest %s;\n' % (bumped, prec.p1())
         repo.ui.write(todo)
@@ -1479,7 +1489,8 @@
     # reroute the working copy parent to the new changeset
     repo.dirstate.setparents(newid, node.nullid)
 
-def _solvedivergent(ui, repo, divergent, dryrun=False, progresscb=None):
+def _solvedivergent(ui, repo, divergent, dryrun=False, confirm=False,
+                    progresscb=None):
     base, others = divergentdata(divergent)
     if len(others) > 1:
         othersstr = "[%s]" % (','.join([str(i) for i in others]))
@@ -1516,13 +1527,15 @@
                               % {'d': divergent, 'o': other})
 
     displayer = cmdutil.show_changeset(ui, repo, {'template': shorttemplate})
-    if not ui.quiet:
+    if not ui.quiet or confirm:
         ui.write(_('merge:'))
         displayer.show(divergent)
         ui.write(_('with: '))
         displayer.show(other)
         ui.write(_('base: '))
         displayer.show(base)
+    if confirm and ui.prompt('perform evolve? [Ny]') != 'y':
+        raise util.Abort(_('evolve aborted by user'))
     if dryrun:
         ui.write('hg update -c %s &&\n' % divergent)
         ui.write('hg merge %s &&\n' % other)
--- a/tests/test-stabilize-result.t	Fri Aug 08 23:11:09 2014 -0700
+++ b/tests/test-stabilize-result.t	Fri Aug 08 23:02:26 2014 -0700
@@ -29,9 +29,10 @@
   $ echo a >> a
   $ hg amend -m changea
   1 new unstable changesets
-  $ hg evolve -v
+  $ hg evolve -v --confirm
   move:[2] changea
   atop:[4] changea
+  perform evolve? [Ny] y
   hg rebase -r cce2c55b8965 -d fb9d051ec0a4
   resolving manifests
   $ glog --hidden
@@ -157,9 +158,10 @@
   hg update 1cf0aacfd363;
   hg revert --all --rev (73b15c7566e9|d5c7ef82d003); (re)
   hg commit --msg "bumped update to %s" (no-eol)
-  $ hg evolve --any
+  $ hg evolve --any --confirm
   recreate:[12] newer a
   atop:[8] newer a
+  perform evolve? [Ny] y
   rebasing to destination parent: 66719795a494
   computing new diff
   committed as (a7cabd7bd9c2|671b9d7eeaec) (re)
@@ -232,7 +234,11 @@
 
 Stabilize it
 
-  $ hg evolve -qn --traceback
+  $ hg evolve -qn --traceback --confirm
+  merge:[19] More addition
+  with: [17] More addition
+  base: [15] More addition
+  perform evolve? [Ny] y
   hg update -c eacc9c8240fe &&
   hg merge d2f173e25686 &&
   hg commit -m "auto merge resolving conflict between eacc9c8240fe and d2f173e25686"&&