comparison mercurial/commands.py @ 45840: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 1bf1dcbc9950
comparison
equal deleted inserted replaced
45839:ebee234d952a 45840:527ce85c2e60
185 use --dry-run/-n to dry run the command. 185 use --dry-run/-n to dry run the command.
186 """ 186 """
187 dryrun = opts.get('dry_run') 187 dryrun = opts.get('dry_run')
188 abortstate = cmdutil.getunfinishedstate(repo) 188 abortstate = cmdutil.getunfinishedstate(repo)
189 if not abortstate: 189 if not abortstate:
190 raise error.Abort(_(b'no operation in progress')) 190 raise error.StateError(_(b'no operation in progress'))
191 if not abortstate.abortfunc: 191 if not abortstate.abortfunc:
192 raise error.InputError( 192 raise error.InputError(
193 ( 193 (
194 _(b"%s in progress but does not support 'hg abort'") 194 _(b"%s in progress but does not support 'hg abort'")
195 % (abortstate._opname) 195 % (abortstate._opname)
1063 changesets = 1 1063 changesets = 1
1064 if noupdate: 1064 if noupdate:
1065 try: 1065 try:
1066 node = state[b'current'][0] 1066 node = state[b'current'][0]
1067 except LookupError: 1067 except LookupError:
1068 raise error.Abort( 1068 raise error.StateError(
1069 _( 1069 _(
1070 b'current bisect revision is unknown - ' 1070 b'current bisect revision is unknown - '
1071 b'start a new bisect to fix' 1071 b'start a new bisect to fix'
1072 ) 1072 )
1073 ) 1073 )
1074 else: 1074 else:
1075 node, p2 = repo.dirstate.parents() 1075 node, p2 = repo.dirstate.parents()
1076 if p2 != nullid: 1076 if p2 != nullid:
1077 raise error.Abort(_(b'current bisect revision is a merge')) 1077 raise error.StateError(_(b'current bisect revision is a merge'))
1078 if rev: 1078 if rev:
1079 node = repo[scmutil.revsingle(repo, rev, node)].node() 1079 node = repo[scmutil.revsingle(repo, rev, node)].node()
1080 with hbisect.restore_state(repo, state, node): 1080 with hbisect.restore_state(repo, state, node):
1081 while changesets: 1081 while changesets:
1082 # update state 1082 # update state
1125 % (extendnode.rev(), extendnode) 1125 % (extendnode.rev(), extendnode)
1126 ) 1126 )
1127 state[b'current'] = [extendnode.node()] 1127 state[b'current'] = [extendnode.node()]
1128 hbisect.save_state(repo, state) 1128 hbisect.save_state(repo, state)
1129 return mayupdate(repo, extendnode.node()) 1129 return mayupdate(repo, extendnode.node())
1130 raise error.Abort(_(b"nothing to extend")) 1130 raise error.StateError(_(b"nothing to extend"))
1131 1131
1132 if changesets == 0: 1132 if changesets == 0:
1133 hbisect.printresult(ui, repo, state, displayer, nodes, good) 1133 hbisect.printresult(ui, repo, state, displayer, nodes, good)
1134 else: 1134 else:
1135 assert len(nodes) == 1 # only a single node can be tested next 1135 assert len(nodes) == 1 # only a single node can be tested next
2333 use --dry-run/-n to dry run the command. 2333 use --dry-run/-n to dry run the command.
2334 """ 2334 """
2335 dryrun = opts.get('dry_run') 2335 dryrun = opts.get('dry_run')
2336 contstate = cmdutil.getunfinishedstate(repo) 2336 contstate = cmdutil.getunfinishedstate(repo)
2337 if not contstate: 2337 if not contstate:
2338 raise error.Abort(_(b'no operation in progress')) 2338 raise error.StateError(_(b'no operation in progress'))
2339 if not contstate.continuefunc: 2339 if not contstate.continuefunc:
2340 raise error.Abort( 2340 raise error.StateError(
2341 ( 2341 (
2342 _(b"%s in progress but does not support 'hg continue'") 2342 _(b"%s in progress but does not support 'hg continue'")
2343 % (contstate._opname) 2343 % (contstate._opname)
2344 ), 2344 ),
2345 hint=contstate.continuemsg(), 2345 hint=contstate.continuemsg(),
3268 3268
3269 3269
3270 def _stopgraft(ui, repo, graftstate): 3270 def _stopgraft(ui, repo, graftstate):
3271 """stop the interrupted graft""" 3271 """stop the interrupted graft"""
3272 if not graftstate.exists(): 3272 if not graftstate.exists():
3273 raise error.Abort(_(b"no interrupted graft found")) 3273 raise error.StateError(_(b"no interrupted graft found"))
3274 pctx = repo[b'.'] 3274 pctx = repo[b'.']
3275 mergemod.clean_update(pctx) 3275 mergemod.clean_update(pctx)
3276 graftstate.delete() 3276 graftstate.delete()
3277 ui.status(_(b"stopped the interrupted graft\n")) 3277 ui.status(_(b"stopped the interrupted graft\n"))
3278 ui.status(_(b"working directory is now at %s\n") % pctx.hex()[:12]) 3278 ui.status(_(b"working directory is now at %s\n") % pctx.hex()[:12])
4765 cmdutil.wrongtooltocontinue(repo, _(b'merge')) 4765 cmdutil.wrongtooltocontinue(repo, _(b'merge'))
4766 cmdutil.check_incompatible_arguments(opts, b'abort', [b'rev', b'preview']) 4766 cmdutil.check_incompatible_arguments(opts, b'abort', [b'rev', b'preview'])
4767 if abort: 4767 if abort:
4768 state = cmdutil.getunfinishedstate(repo) 4768 state = cmdutil.getunfinishedstate(repo)
4769 if state and state._opname != b'merge': 4769 if state and state._opname != b'merge':
4770 raise error.Abort( 4770 raise error.StateError(
4771 _(b'cannot abort merge with %s in progress') % (state._opname), 4771 _(b'cannot abort merge with %s in progress') % (state._opname),
4772 hint=state.hint(), 4772 hint=state.hint(),
4773 ) 4773 )
4774 if node: 4774 if node:
4775 raise error.InputError(_(b"cannot specify a node with --abort")) 4775 raise error.InputError(_(b"cannot specify a node with --abort"))
5891 5891
5892 with repo.wlock(): 5892 with repo.wlock():
5893 ms = mergestatemod.mergestate.read(repo) 5893 ms = mergestatemod.mergestate.read(repo)
5894 5894
5895 if not (ms.active() or repo.dirstate.p2() != nullid): 5895 if not (ms.active() or repo.dirstate.p2() != nullid):
5896 raise error.Abort( 5896 raise error.StateError(
5897 _(b'resolve command not applicable when not merging') 5897 _(b'resolve command not applicable when not merging')
5898 ) 5898 )
5899 5899
5900 wctx = repo[None] 5900 wctx = repo[None]
5901 m = scmutil.match(wctx, pats, opts) 5901 m = scmutil.match(wctx, pats, opts)
5983 + b''.join( 5983 + b''.join(
5984 b' ' + uipathfn(f) + b'\n' for f in hasconflictmarkers 5984 b' ' + uipathfn(f) + b'\n' for f in hasconflictmarkers
5985 ) 5985 )
5986 ) 5986 )
5987 if markcheck == b'abort' and not all and not pats: 5987 if markcheck == b'abort' and not all and not pats:
5988 raise error.Abort( 5988 raise error.StateError(
5989 _(b'conflict markers detected'), 5989 _(b'conflict markers detected'),
5990 hint=_(b'use --all to mark anyway'), 5990 hint=_(b'use --all to mark anyway'),
5991 ) 5991 )
5992 5992
5993 for f in tocomplete: 5993 for f in tocomplete:
7183 _(b"tag '%s' already exists (use -f to force)") % n 7183 _(b"tag '%s' already exists (use -f to force)") % n
7184 ) 7184 )
7185 if not opts.get(b'local'): 7185 if not opts.get(b'local'):
7186 p1, p2 = repo.dirstate.parents() 7186 p1, p2 = repo.dirstate.parents()
7187 if p2 != nullid: 7187 if p2 != nullid:
7188 raise error.Abort(_(b'uncommitted merge')) 7188 raise error.StateError(_(b'uncommitted merge'))
7189 bheads = repo.branchheads() 7189 bheads = repo.branchheads()
7190 if not opts.get(b'force') and bheads and p1 not in bheads: 7190 if not opts.get(b'force') and bheads and p1 not in bheads:
7191 raise error.InputError( 7191 raise error.InputError(
7192 _( 7192 _(
7193 b'working directory is not at a branch head ' 7193 b'working directory is not at a branch head '