hgext/evolve.py
changeset 1047 d830377bf186
parent 1046 296d48e1f55a
child 1052 ac47c2f774a8
--- 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)