Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/cmdutil.py @ 45859:527ce85c2e60
errors: introduce StateError and use it from commands and cmdutil
This very similar to an earlier patch (which was for `InputError`).
In this patch, I also updated the transplant extension only because
`test-transplant.t` would otherwise have needed a `#if continueflag`.
Differential Revision: https://phab.mercurial-scm.org/D9310
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Mon, 12 Oct 2020 12:44:18 -0700 |
parents | 8d72e29ad1e0 |
children | 96ca817ec192 |
comparison
equal
deleted
inserted
replaced
45858:ebee234d952a | 45859:527ce85c2e60 |
---|---|
1085 | 1085 |
1086 'hint' is the usual hint given to Abort exception. | 1086 'hint' is the usual hint given to Abort exception. |
1087 """ | 1087 """ |
1088 | 1088 |
1089 if merge and repo.dirstate.p2() != nullid: | 1089 if merge and repo.dirstate.p2() != nullid: |
1090 raise error.Abort(_(b'outstanding uncommitted merge'), hint=hint) | 1090 raise error.StateError(_(b'outstanding uncommitted merge'), hint=hint) |
1091 st = repo.status() | 1091 st = repo.status() |
1092 if st.modified or st.added or st.removed or st.deleted: | 1092 if st.modified or st.added or st.removed or st.deleted: |
1093 raise error.Abort(_(b'uncommitted changes'), hint=hint) | 1093 raise error.StateError(_(b'uncommitted changes'), hint=hint) |
1094 ctx = repo[None] | 1094 ctx = repo[None] |
1095 for s in sorted(ctx.substate): | 1095 for s in sorted(ctx.substate): |
1096 ctx.sub(s).bailifchanged(hint=hint) | 1096 ctx.sub(s).bailifchanged(hint=hint) |
1097 | 1097 |
1098 | 1098 |
3736 or (commit and state._allowcommit) | 3736 or (commit and state._allowcommit) |
3737 or state._reportonly | 3737 or state._reportonly |
3738 ): | 3738 ): |
3739 continue | 3739 continue |
3740 if state.isunfinished(repo): | 3740 if state.isunfinished(repo): |
3741 raise error.Abort(state.msg(), hint=state.hint()) | 3741 raise error.StateError(state.msg(), hint=state.hint()) |
3742 | 3742 |
3743 for s in statemod._unfinishedstates: | 3743 for s in statemod._unfinishedstates: |
3744 if ( | 3744 if ( |
3745 not s._clearable | 3745 not s._clearable |
3746 or (commit and s._allowcommit) | 3746 or (commit and s._allowcommit) |
3747 or (s._opname == b'merge' and skipmerge) | 3747 or (s._opname == b'merge' and skipmerge) |
3748 or s._reportonly | 3748 or s._reportonly |
3749 ): | 3749 ): |
3750 continue | 3750 continue |
3751 if s.isunfinished(repo): | 3751 if s.isunfinished(repo): |
3752 raise error.Abort(s.msg(), hint=s.hint()) | 3752 raise error.StateError(s.msg(), hint=s.hint()) |
3753 | 3753 |
3754 | 3754 |
3755 def clearunfinished(repo): | 3755 def clearunfinished(repo): |
3756 '''Check for unfinished operations (as above), and clear the ones | 3756 '''Check for unfinished operations (as above), and clear the ones |
3757 that are clearable. | 3757 that are clearable. |
3758 ''' | 3758 ''' |
3759 for state in statemod._unfinishedstates: | 3759 for state in statemod._unfinishedstates: |
3760 if state._reportonly: | 3760 if state._reportonly: |
3761 continue | 3761 continue |
3762 if not state._clearable and state.isunfinished(repo): | 3762 if not state._clearable and state.isunfinished(repo): |
3763 raise error.Abort(state.msg(), hint=state.hint()) | 3763 raise error.StateError(state.msg(), hint=state.hint()) |
3764 | 3764 |
3765 for s in statemod._unfinishedstates: | 3765 for s in statemod._unfinishedstates: |
3766 if s._opname == b'merge' or state._reportonly: | 3766 if s._opname == b'merge' or state._reportonly: |
3767 continue | 3767 continue |
3768 if s._clearable and s.isunfinished(repo): | 3768 if s._clearable and s.isunfinished(repo): |
3827 ''' | 3827 ''' |
3828 after = howtocontinue(repo) | 3828 after = howtocontinue(repo) |
3829 hint = None | 3829 hint = None |
3830 if after[1]: | 3830 if after[1]: |
3831 hint = after[0] | 3831 hint = after[0] |
3832 raise error.Abort(_(b'no %s in progress') % task, hint=hint) | 3832 raise error.StateError(_(b'no %s in progress') % task, hint=hint) |
3833 | 3833 |
3834 | 3834 |
3835 def abortgraft(ui, repo, graftstate): | 3835 def abortgraft(ui, repo, graftstate): |
3836 """abort the interrupted graft and rollbacks to the state before interrupted | 3836 """abort the interrupted graft and rollbacks to the state before interrupted |
3837 graft""" | 3837 graft""" |
3838 if not graftstate.exists(): | 3838 if not graftstate.exists(): |
3839 raise error.Abort(_(b"no interrupted graft to abort")) | 3839 raise error.StateError(_(b"no interrupted graft to abort")) |
3840 statedata = readgraftstate(repo, graftstate) | 3840 statedata = readgraftstate(repo, graftstate) |
3841 newnodes = statedata.get(b'newnodes') | 3841 newnodes = statedata.get(b'newnodes') |
3842 if newnodes is None: | 3842 if newnodes is None: |
3843 # and old graft state which does not have all the data required to abort | 3843 # and old graft state which does not have all the data required to abort |
3844 # the graft | 3844 # the graft |