diff hgext/rebase.py @ 38667:572dff5c946e

rebase: add --confirm option This feature adds a functionality in rebase to confirm before applying changes. When there is no conflict and user confirm to apply actions, we just finish the unfinished rebase. But when there is a conflict and user confirm to apply actions then we can't just finish rebasing using rbsrt._finishrebase() because in-memory merge doesn't support conflicts, so we have to abort and run on-disk merge in this case. And if user doesn't confirm to apply actions then simply abort the rebase. Differential Revision: https://phab.mercurial-scm.org/D3870
author Sushil khanchi <sushilkhanchi97@gmail.com>
date Sat, 30 Jun 2018 12:42:49 +0530
parents a06b2b032557
children 99ed6e2f6606
line wrap: on
line diff
--- a/hgext/rebase.py	Wed Jul 11 16:29:23 2018 -0700
+++ b/hgext/rebase.py	Sat Jun 30 12:42:49 2018 +0530
@@ -677,7 +677,7 @@
     ('a', 'abort', False, _('abort an interrupted rebase')),
     ('', 'auto-orphans', '', _('automatically rebase orphan revisions '
                                'in the specified revset (EXPERIMENTAL)')),
-     ] + cmdutil.dryrunopts + cmdutil.formatteropts,
+     ] + cmdutil.dryrunopts + cmdutil.formatteropts + cmdutil.confirmopts,
     _('[-s REV | -b REV] [-d REV] [OPTION]'))
 def rebase(ui, repo, **opts):
     """move changeset (and descendants) to a different branch
@@ -808,6 +808,14 @@
             raise error.Abort(_('cannot specify both --dry-run and --abort'))
         if opts.get('continue'):
             raise error.Abort(_('cannot specify both --dry-run and --continue'))
+    if opts.get('confirm'):
+        dryrun = True
+        if opts.get('dry_run'):
+            raise error.Abort(_('cannot specify both --confirm and --dry-run'))
+        if opts.get('abort'):
+            raise error.Abort(_('cannot specify both --confirm and --abort'))
+        if opts.get('continue'):
+            raise error.Abort(_('cannot specify both --confirm and --continue'))
 
     if (opts.get('continue') or opts.get('abort') or
         repo.currenttransaction() is not None):
@@ -844,8 +852,14 @@
 
 def _dryrunrebase(ui, repo, opts):
     rbsrt = rebaseruntime(repo, ui, inmemory=True, opts=opts)
-    ui.status(_('starting dry-run rebase; repository will not be changed\n'))
+    confirm = opts.get('confirm')
+    if confirm:
+        ui.status(_('starting rebase...\n'))
+    else:
+        ui.status(_('starting dry-run rebase; repository will not be '
+                    'changed\n'))
     with repo.wlock(), repo.lock():
+        needsabort = True
         try:
             overrides = {('rebase', 'singletransaction'): True}
             with ui.configoverride(overrides, 'rebase'):
@@ -853,15 +867,35 @@
                             leaveunfinished=True)
         except error.InMemoryMergeConflictsError:
             ui.status(_('hit a merge conflict\n'))
+            if confirm:
+                # abort as in-memory merge doesn't support conflict
+                rbsrt._prepareabortorcontinue(isabort=True, backup=False,
+                                              suppwarns=True)
+                needsabort = False
+                if not ui.promptchoice(_(b'apply changes (yn)?'
+                                         b'$$ &Yes $$ &No')):
+                    _dorebase(ui, repo, opts, inmemory=False)
             return 1
         else:
-            ui.status(_('dry-run rebase completed successfully; run without '
-                        '-n/--dry-run to perform this rebase\n'))
+            if confirm:
+                ui.status(_('rebase completed successfully\n'))
+                if not ui.promptchoice(_(b'apply changes (yn)?'
+                                         b'$$ &Yes $$ &No')):
+                    # finish unfinished rebase
+                    rbsrt._finishrebase()
+                else:
+                    rbsrt._prepareabortorcontinue(isabort=True, backup=False,
+                                                  suppwarns=True)
+                needsabort = False
+            else:
+                ui.status(_('dry-run rebase completed successfully; run without'
+                            ' -n/--dry-run to perform this rebase\n'))
             return 0
         finally:
-            # no need to store backup in case of dryrun
-            rbsrt._prepareabortorcontinue(isabort=True, backup=False,
-                                          suppwarns=True)
+            if needsabort:
+                # no need to store backup in case of dryrun
+                rbsrt._prepareabortorcontinue(isabort=True, backup=False,
+                                              suppwarns=True)
 
 def _dorebase(ui, repo, opts, inmemory=False):
     rbsrt = rebaseruntime(repo, ui, inmemory, opts)