Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
38666:a06b2b032557 | 38667:572dff5c946e |
---|---|
675 ('t', 'tool', '', _('specify merge tool')), | 675 ('t', 'tool', '', _('specify merge tool')), |
676 ('c', 'continue', False, _('continue an interrupted rebase')), | 676 ('c', 'continue', False, _('continue an interrupted rebase')), |
677 ('a', 'abort', False, _('abort an interrupted rebase')), | 677 ('a', 'abort', False, _('abort an interrupted rebase')), |
678 ('', 'auto-orphans', '', _('automatically rebase orphan revisions ' | 678 ('', 'auto-orphans', '', _('automatically rebase orphan revisions ' |
679 'in the specified revset (EXPERIMENTAL)')), | 679 'in the specified revset (EXPERIMENTAL)')), |
680 ] + cmdutil.dryrunopts + cmdutil.formatteropts, | 680 ] + cmdutil.dryrunopts + cmdutil.formatteropts + cmdutil.confirmopts, |
681 _('[-s REV | -b REV] [-d REV] [OPTION]')) | 681 _('[-s REV | -b REV] [-d REV] [OPTION]')) |
682 def rebase(ui, repo, **opts): | 682 def rebase(ui, repo, **opts): |
683 """move changeset (and descendants) to a different branch | 683 """move changeset (and descendants) to a different branch |
684 | 684 |
685 Rebase uses repeated merging to graft changesets from one part of | 685 Rebase uses repeated merging to graft changesets from one part of |
806 if dryrun: | 806 if dryrun: |
807 if opts.get('abort'): | 807 if opts.get('abort'): |
808 raise error.Abort(_('cannot specify both --dry-run and --abort')) | 808 raise error.Abort(_('cannot specify both --dry-run and --abort')) |
809 if opts.get('continue'): | 809 if opts.get('continue'): |
810 raise error.Abort(_('cannot specify both --dry-run and --continue')) | 810 raise error.Abort(_('cannot specify both --dry-run and --continue')) |
811 if opts.get('confirm'): | |
812 dryrun = True | |
813 if opts.get('dry_run'): | |
814 raise error.Abort(_('cannot specify both --confirm and --dry-run')) | |
815 if opts.get('abort'): | |
816 raise error.Abort(_('cannot specify both --confirm and --abort')) | |
817 if opts.get('continue'): | |
818 raise error.Abort(_('cannot specify both --confirm and --continue')) | |
811 | 819 |
812 if (opts.get('continue') or opts.get('abort') or | 820 if (opts.get('continue') or opts.get('abort') or |
813 repo.currenttransaction() is not None): | 821 repo.currenttransaction() is not None): |
814 # in-memory rebase is not compatible with resuming rebases. | 822 # in-memory rebase is not compatible with resuming rebases. |
815 # (Or if it is run within a transaction, since the restart logic can | 823 # (Or if it is run within a transaction, since the restart logic can |
842 else: | 850 else: |
843 return _dorebase(ui, repo, opts) | 851 return _dorebase(ui, repo, opts) |
844 | 852 |
845 def _dryrunrebase(ui, repo, opts): | 853 def _dryrunrebase(ui, repo, opts): |
846 rbsrt = rebaseruntime(repo, ui, inmemory=True, opts=opts) | 854 rbsrt = rebaseruntime(repo, ui, inmemory=True, opts=opts) |
847 ui.status(_('starting dry-run rebase; repository will not be changed\n')) | 855 confirm = opts.get('confirm') |
856 if confirm: | |
857 ui.status(_('starting rebase...\n')) | |
858 else: | |
859 ui.status(_('starting dry-run rebase; repository will not be ' | |
860 'changed\n')) | |
848 with repo.wlock(), repo.lock(): | 861 with repo.wlock(), repo.lock(): |
862 needsabort = True | |
849 try: | 863 try: |
850 overrides = {('rebase', 'singletransaction'): True} | 864 overrides = {('rebase', 'singletransaction'): True} |
851 with ui.configoverride(overrides, 'rebase'): | 865 with ui.configoverride(overrides, 'rebase'): |
852 _origrebase(ui, repo, opts, rbsrt, inmemory=True, | 866 _origrebase(ui, repo, opts, rbsrt, inmemory=True, |
853 leaveunfinished=True) | 867 leaveunfinished=True) |
854 except error.InMemoryMergeConflictsError: | 868 except error.InMemoryMergeConflictsError: |
855 ui.status(_('hit a merge conflict\n')) | 869 ui.status(_('hit a merge conflict\n')) |
870 if confirm: | |
871 # abort as in-memory merge doesn't support conflict | |
872 rbsrt._prepareabortorcontinue(isabort=True, backup=False, | |
873 suppwarns=True) | |
874 needsabort = False | |
875 if not ui.promptchoice(_(b'apply changes (yn)?' | |
876 b'$$ &Yes $$ &No')): | |
877 _dorebase(ui, repo, opts, inmemory=False) | |
856 return 1 | 878 return 1 |
857 else: | 879 else: |
858 ui.status(_('dry-run rebase completed successfully; run without ' | 880 if confirm: |
859 '-n/--dry-run to perform this rebase\n')) | 881 ui.status(_('rebase completed successfully\n')) |
882 if not ui.promptchoice(_(b'apply changes (yn)?' | |
883 b'$$ &Yes $$ &No')): | |
884 # finish unfinished rebase | |
885 rbsrt._finishrebase() | |
886 else: | |
887 rbsrt._prepareabortorcontinue(isabort=True, backup=False, | |
888 suppwarns=True) | |
889 needsabort = False | |
890 else: | |
891 ui.status(_('dry-run rebase completed successfully; run without' | |
892 ' -n/--dry-run to perform this rebase\n')) | |
860 return 0 | 893 return 0 |
861 finally: | 894 finally: |
862 # no need to store backup in case of dryrun | 895 if needsabort: |
863 rbsrt._prepareabortorcontinue(isabort=True, backup=False, | 896 # no need to store backup in case of dryrun |
864 suppwarns=True) | 897 rbsrt._prepareabortorcontinue(isabort=True, backup=False, |
898 suppwarns=True) | |
865 | 899 |
866 def _dorebase(ui, repo, opts, inmemory=False): | 900 def _dorebase(ui, repo, opts, inmemory=False): |
867 rbsrt = rebaseruntime(repo, ui, inmemory, opts) | 901 rbsrt = rebaseruntime(repo, ui, inmemory, opts) |
868 return _origrebase(ui, repo, opts, rbsrt, inmemory=inmemory) | 902 return _origrebase(ui, repo, opts, rbsrt, inmemory=inmemory) |
869 | 903 |