Mercurial > hg
diff hgext/rebase.py @ 38372:f4f1fb1cbfb4
rebase: add dry-run functionality
For now, it gives stats about rebase would be successful or hit a
conflict. Remaining work is to improve the output and adding verbose mode
where will show the diff of conflicting files if we hit any.
Differential Revision: https://phab.mercurial-scm.org/D3757
author | Sushil khanchi <sushilkhanchi97@gmail.com> |
---|---|
date | Sat, 16 Jun 2018 08:22:10 +0530 |
parents | ead71b15efd5 |
children | a73eab7d6575 |
line wrap: on
line diff
--- a/hgext/rebase.py Mon Jun 18 16:07:46 2018 +0530 +++ b/hgext/rebase.py Sat Jun 16 08:22:10 2018 +0530 @@ -673,8 +673,7 @@ ('a', 'abort', False, _('abort an interrupted rebase')), ('', 'auto-orphans', '', _('automatically rebase orphan revisions ' 'in the specified revset (EXPERIMENTAL)')), - ] + - cmdutil.formatteropts, + ] + cmdutil.dryrunopts + cmdutil.formatteropts, _('[-s REV | -b REV] [-d REV] [OPTION]')) def rebase(ui, repo, **opts): """move changeset (and descendants) to a different branch @@ -798,6 +797,13 @@ """ inmemory = ui.configbool('rebase', 'experimental.inmemory') + dryrun = opts.get(r'dry_run') + if dryrun: + if opts.get(r'abort'): + raise error.Abort(_('cannot specify both --dry-run and --abort')) + if opts.get(r'continue'): + raise error.Abort(_('cannot specify both --dry-run and --continue')) + if (opts.get(r'continue') or opts.get(r'abort') or repo.currenttransaction() is not None): # in-memory rebase is not compatible with resuming rebases. @@ -814,7 +820,19 @@ opts[r'rev'] = [revsetlang.formatspec('%ld and orphan()', userrevs)] opts[r'dest'] = '_destautoorphanrebase(SRC)' - if inmemory: + if dryrun: + try: + overrides = {('rebase', 'singletransaction'): True} + with ui.configoverride(overrides, 'rebase'): + _origrebase(ui, repo, inmemory=True, leaveunfinished=True, + **opts) + except error.InMemoryMergeConflictsError: + ui.status(_('hit a merge conflict\n')) + else: + ui.status(_('there will be no conflict, you can rebase\n')) + finally: + _origrebase(ui, repo, abort=True) + elif inmemory: try: # in-memory merge doesn't support conflicts, so if we hit any, abort # and re-run as an on-disk merge. @@ -824,12 +842,12 @@ except error.InMemoryMergeConflictsError: ui.warn(_('hit merge conflicts; re-running rebase without in-memory' ' merge\n')) - _origrebase(ui, repo, **{r'abort': True}) + _origrebase(ui, repo, abort=True) return _origrebase(ui, repo, inmemory=False, **opts) else: return _origrebase(ui, repo, **opts) -def _origrebase(ui, repo, inmemory=False, **opts): +def _origrebase(ui, repo, inmemory=False, leaveunfinished=False, **opts): opts = pycompat.byteskwargs(opts) rbsrt = rebaseruntime(repo, ui, inmemory, opts) @@ -902,7 +920,8 @@ dsguard = dirstateguard.dirstateguard(repo, 'rebase') with util.acceptintervention(dsguard): rbsrt._performrebase(tr) - rbsrt._finishrebase() + if not leaveunfinished: + rbsrt._finishrebase() def _definedestmap(ui, repo, inmemory, destf=None, srcf=None, basef=None, revf=None, destspace=None):