This instance will be upgraded to Heptapod 0.21.0rc3 on 2021-04-23 at 10:30 UTC+2 (a few minutes of down time)

Commit bf8af55d authored by Martin von Zweigbergk's avatar Martin von Zweigbergk

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
parent ebee234d952a
......@@ -804,10 +804,10 @@ def _dotransplant(ui, repo, *revs, **opts):
raise error.Abort(_(b'no revision checked out'))
if opts.get(b'continue'):
if not tp.canresume():
raise error.Abort(_(b'no transplant to continue'))
raise error.StateError(_(b'no transplant to continue'))
elif opts.get(b'stop'):
if not tp.canresume():
raise error.Abort(_(b'no interrupted transplant found'))
raise error.StateError(_(b'no interrupted transplant found'))
return tp.stop(ui, repo)
else:
cmdutil.checkunfinished(repo)
......
......@@ -1087,10 +1087,10 @@ def bailifchanged(repo, merge=True, hint=None):
"""
if merge and repo.dirstate.p2() != nullid:
raise error.Abort(_(b'outstanding uncommitted merge'), hint=hint)
raise error.StateError(_(b'outstanding uncommitted merge'), hint=hint)
st = repo.status()
if st.modified or st.added or st.removed or st.deleted:
raise error.Abort(_(b'uncommitted changes'), hint=hint)
raise error.StateError(_(b'uncommitted changes'), hint=hint)
ctx = repo[None]
for s in sorted(ctx.substate):
ctx.sub(s).bailifchanged(hint=hint)
......@@ -3738,7 +3738,7 @@ def checkunfinished(repo, commit=False, skipmerge=False):
):
continue
if state.isunfinished(repo):
raise error.Abort(state.msg(), hint=state.hint())
raise error.StateError(state.msg(), hint=state.hint())
for s in statemod._unfinishedstates:
if (
......@@ -3749,7 +3749,7 @@ def checkunfinished(repo, commit=False, skipmerge=False):
):
continue
if s.isunfinished(repo):
raise error.Abort(s.msg(), hint=s.hint())
raise error.StateError(s.msg(), hint=s.hint())
def clearunfinished(repo):
......@@ -3760,7 +3760,7 @@ def clearunfinished(repo):
if state._reportonly:
continue
if not state._clearable and state.isunfinished(repo):
raise error.Abort(state.msg(), hint=state.hint())
raise error.StateError(state.msg(), hint=state.hint())
for s in statemod._unfinishedstates:
if s._opname == b'merge' or state._reportonly:
......@@ -3829,14 +3829,14 @@ def wrongtooltocontinue(repo, task):
hint = None
if after[1]:
hint = after[0]
raise error.Abort(_(b'no %s in progress') % task, hint=hint)
raise error.StateError(_(b'no %s in progress') % task, hint=hint)
def abortgraft(ui, repo, graftstate):
"""abort the interrupted graft and rollbacks to the state before interrupted
graft"""
if not graftstate.exists():
raise error.Abort(_(b"no interrupted graft to abort"))
raise error.StateError(_(b"no interrupted graft to abort"))
statedata = readgraftstate(repo, graftstate)
newnodes = statedata.get(b'newnodes')
if newnodes is None:
......
......@@ -187,7 +187,7 @@ def abort(ui, repo, **opts):
dryrun = opts.get('dry_run')
abortstate = cmdutil.getunfinishedstate(repo)
if not abortstate:
raise error.Abort(_(b'no operation in progress'))
raise error.StateError(_(b'no operation in progress'))
if not abortstate.abortfunc:
raise error.InputError(
(
......@@ -1065,7 +1065,7 @@ def bisect(
try:
node = state[b'current'][0]
except LookupError:
raise error.Abort(
raise error.StateError(
_(
b'current bisect revision is unknown - '
b'start a new bisect to fix'
......@@ -1074,7 +1074,7 @@ def bisect(
else:
node, p2 = repo.dirstate.parents()
if p2 != nullid:
raise error.Abort(_(b'current bisect revision is a merge'))
raise error.StateError(_(b'current bisect revision is a merge'))
if rev:
node = repo[scmutil.revsingle(repo, rev, node)].node()
with hbisect.restore_state(repo, state, node):
......@@ -1127,7 +1127,7 @@ def bisect(
state[b'current'] = [extendnode.node()]
hbisect.save_state(repo, state)
return mayupdate(repo, extendnode.node())
raise error.Abort(_(b"nothing to extend"))
raise error.StateError(_(b"nothing to extend"))
if changesets == 0:
hbisect.printresult(ui, repo, state, displayer, nodes, good)
......@@ -2335,9 +2335,9 @@ def continuecmd(ui, repo, **opts):
dryrun = opts.get('dry_run')
contstate = cmdutil.getunfinishedstate(repo)
if not contstate:
raise error.Abort(_(b'no operation in progress'))
raise error.StateError(_(b'no operation in progress'))
if not contstate.continuefunc:
raise error.Abort(
raise error.StateError(
(
_(b"%s in progress but does not support 'hg continue'")
% (contstate._opname)
......@@ -3270,7 +3270,7 @@ def _dograft(ui, repo, *revs, **opts):
def _stopgraft(ui, repo, graftstate):
"""stop the interrupted graft"""
if not graftstate.exists():
raise error.Abort(_(b"no interrupted graft found"))
raise error.StateError(_(b"no interrupted graft found"))
pctx = repo[b'.']
mergemod.clean_update(pctx)
graftstate.delete()
......@@ -4767,7 +4767,7 @@ def merge(ui, repo, node=None, **opts):
if abort:
state = cmdutil.getunfinishedstate(repo)
if state and state._opname != b'merge':
raise error.Abort(
raise error.StateError(
_(b'cannot abort merge with %s in progress') % (state._opname),
hint=state.hint(),
)
......@@ -5893,7 +5893,7 @@ def resolve(ui, repo, *pats, **opts):
ms = mergestatemod.mergestate.read(repo)
if not (ms.active() or repo.dirstate.p2() != nullid):
raise error.Abort(
raise error.StateError(
_(b'resolve command not applicable when not merging')
)
......@@ -5985,7 +5985,7 @@ def resolve(ui, repo, *pats, **opts):
)
)
if markcheck == b'abort' and not all and not pats:
raise error.Abort(
raise error.StateError(
_(b'conflict markers detected'),
hint=_(b'use --all to mark anyway'),
)
......@@ -7185,7 +7185,7 @@ def tag(ui, repo, name1, *names, **opts):
if not opts.get(b'local'):
p1, p2 = repo.dirstate.parents()
if p2 != nullid:
raise error.Abort(_(b'uncommitted merge'))
raise error.StateError(_(b'uncommitted merge'))
bheads = repo.branchheads()
if not opts.get(b'force') and bheads and p1 not in bheads:
raise error.InputError(
......
......@@ -188,6 +188,13 @@ class InputError(Abort):
"""
class StateError(Abort):
"""Indicates that the operation might work if retried in a different state.
Examples: Unresolved merge conflicts, unfinished operations.
"""
class HookLoadError(Abort):
"""raised when loading a hook fails, aborting an operation
......
......@@ -224,6 +224,8 @@ def callcatch(ui, func):
except error.Abort as inst:
if isinstance(inst, error.InputError):
detailed_exit_code = 10
elif isinstance(inst, error.StateError):
detailed_exit_code = 20
ui.error(_(b"abort: %s\n") % inst.message)
if inst.hint:
ui.error(_(b"(%s)\n") % inst.hint)
......
......@@ -26,5 +26,5 @@ Abort absorb if there is an unfinished operation.
$ hg --config extensions.rebase= absorb
abort: rebase in progress
(use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
[255]
[20]
......@@ -65,7 +65,7 @@ Change with dirty working directory
$ echo bar > a
$ hg branch -r . foo
abort: uncommitted changes
[255]
[20]
$ hg revert --all
reverting a
......@@ -331,7 +331,7 @@ Changing branch of a merge commit
(branch merge, don't forget to commit)
$ hg branch -r . abcd
abort: outstanding uncommitted merge
[255]
[20]
$ hg ci -m "Merge commit"
$ hg glog -r 'parents(.)::'
......
......@@ -47,7 +47,7 @@ Testing the abort functionality first in case of conflicts
$ hg abort
abort: no merge in progress (abortflag !)
abort: no operation in progress (abortcommand !)
[255]
[20]
$ hg merge
merging A
......
......@@ -157,7 +157,7 @@ should abort, because i is modified
$ hg --cwd i fetch ../h
abort: uncommitted changes
[255]
[20]
test fetch with named branches
......
......@@ -879,7 +879,7 @@ fixing the working directory if there are unresolved merge conflicts.
$ hg --config extensions.rebase= fix -r .
abort: rebase in progress
(use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
[255]
[20]
$ cd ..
......
......@@ -238,7 +238,7 @@ Testing the --stop flag of `hg graft` which stops the interrupted graft
$ hg graft --stop
abort: no interrupted graft found
[255]
[20]
$ hg graft -r 3
grafting 3:9150fe93bec6 "added d"
......@@ -342,7 +342,7 @@ before the graft
$ hg abort
abort: no interrupted graft to abort (abortflag !)
abort: no operation in progress (abortcommand !)
[255]
[20]
when stripping is required
$ hg graft -r 4 -r 5
......
......@@ -85,7 +85,7 @@ Can't continue without starting:
$ hg rm -q e
$ hg graft --continue
abort: no graft in progress
[255]
[20]
$ hg revert -r . -q e
Need to specify a rev:
......@@ -130,7 +130,7 @@ Can't graft with dirty wd:
$ echo foo > a
$ hg graft 1
abort: uncommitted changes
[255]
[20]
$ hg revert a
Graft a rename:
......@@ -292,7 +292,7 @@ Commit while interrupted should fail:
$ hg ci -m 'commit interrupted graft'
abort: graft in progress
(use 'hg graft --continue' or 'hg graft --stop' to stop)
[255]
[20]
Abort the graft and try committing:
......
......@@ -55,11 +55,11 @@ histedit --continue/--abort with no existing state
$ hg histedit --continue
abort: no histedit in progress
[255]
[20]
$ hg abort
abort: no histedit in progress (abortflag !)
abort: no operation in progress (abortcommand !)
[255]
[20]
Run a dummy edit to make sure we get tip^^ correctly via revsingle.
--------------------------------------------------------------------
......@@ -156,7 +156,7 @@ temporarily.
$ hg graft --continue
abort: no graft in progress
(continue: hg histedit --continue)
[255]
[20]
$ mv .hg/histedit-state .hg/histedit-state.back
$ hg update --quiet --clean 2
......@@ -505,7 +505,7 @@ in which case this test should be revisited.
$ hg commit --amend -m 'reject this fold'
abort: histedit in progress
(use 'hg histedit --continue' or 'hg histedit --abort')
[255]
[20]
With markers enabled, histedit does not get confused, and
amend should not be blocked by the ongoing histedit.
......
......@@ -63,7 +63,7 @@ dirty a file
$ hg histedit 177f92b77385 --commands - 2>&1 << EOF
> EOF
abort: uncommitted changes
[255]
[20]
$ echo g > g
edit the history
......@@ -82,7 +82,7 @@ try to update and get an error
$ hg update tip
abort: histedit in progress
(use 'hg histedit --continue' or 'hg histedit --abort')
[255]
[20]
edit the plan via the editor
$ cat >> $TESTTMP/editplan.sh <<EOF
......@@ -136,7 +136,7 @@ Go at a random point and try to continue
$ hg up 0
abort: histedit in progress
(use 'hg histedit --continue' or 'hg histedit --abort')
[255]
[20]
Try to delete necessary commit
$ hg strip -r 652413b
......@@ -153,7 +153,7 @@ qnew should fail while we're in the middle of the edit step
$ hg --config extensions.mq= qnew please-fail
abort: histedit in progress
(use 'hg histedit --continue' or 'hg histedit --abort')
[255]
[20]
$ HGEDITOR='echo foobaz > ' hg histedit --continue 2>&1 | fixbundle
$ hg log --graph
......
......@@ -60,7 +60,7 @@ Invert the order of the commits, and pretend the merge succeeded.
7181f42b8fca: skipping changeset (no changes)
$ hg histedit --abort
abort: no histedit in progress
[255]
[20]
$ cd ..
Test legacy config name
......
......@@ -169,7 +169,7 @@ abort editing session, after first forcibly updating away
$ hg up 0
abort: histedit in progress
(use 'hg histedit --continue' or 'hg histedit --abort')
[255]
[20]
$ mv .hg/histedit-state .hg/histedit-state-ignore
$ hg up 0
0 files updated, 0 files merged, 3 files removed, 0 files unresolved
......
......@@ -125,7 +125,7 @@ TODO: Ideally, this should mention the largefile, not the standin
$ hg clone -q . ../fetch
$ hg --config extensions.fetch= fetch ../fetch
abort: uncommitted changes
[255]
[20]
$ hg up -qC
$ cd ..
......
......@@ -46,7 +46,7 @@ noticed by `update --check` in the top level repo.
$ hg up --check -r '.^'
abort: uncommitted changes
[255]
[20]
$ hg st -S
! a
$ hg up -Cq .
......
......@@ -36,7 +36,7 @@ of the files in a commit we're updating to
$ hg ci
abort: last update was interrupted
(use 'hg update' to get a consistent checkout)
[255]
[20]
$ hg sum
parent: 0:538afb845929
commit #0
......
......@@ -16,7 +16,7 @@
$ rm b
$ hg update -c 2
abort: uncommitted changes
[255]
[20]
$ hg revert b
$ hg update -c 2
0 files updated, 0 files merged, 1 files removed, 0 files unresolved
......
......@@ -812,7 +812,7 @@ strip with local changes, should complain
$ hg add y
$ hg strip tip
abort: uncommitted changes
[255]
[20]
--force strip with local changes
......
......@@ -129,7 +129,7 @@ Update - local renamed file conflicts with remote directory
R base
$ hg up --check dir
abort: uncommitted changes
[255]
[20]
$ hg up dir
a: path conflict - a file or link has the same name as a directory
the local file has been renamed to a~d20a80d4def3
......@@ -154,7 +154,7 @@ Update clean - local directory conflicts with changed remote file
$ echo 9 > a/b/c
$ hg up file2 --check --config merge.checkunknown=warn
abort: uncommitted changes
[255]
[20]
$ hg up file2 --clean
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(activating bookmark file2)
......@@ -29,7 +29,7 @@ Should respect config to disable dirty update
new changesets 107cefe13e42
1 local changesets published
abort: uncommitted changes
[255]
[20]
$ hg --config extensions.strip= strip --no-backup tip
$ hg co -qC tip
......
......@@ -470,4 +470,4 @@ qrecord should throw an error when histedit in process
> EOF
abort: histedit in progress
(use 'hg histedit --continue' or 'hg histedit --abort')
[255]
[20]
......@@ -328,7 +328,7 @@ user has somehow managed to update to a different revision (issue4009)
$ hg up 1 # user gets an error saying to run hg rebase --abort
abort: rebase in progress
(use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
[255]
[20]
$ cat a
new
......@@ -398,20 +398,20 @@ New operations are blocked with the correct state message
$ hg rebase -s 3 -d tip
abort: rebase in progress
(use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
[255]
[20]
$ hg up .
abort: rebase in progress
(use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
[255]
[20]
$ hg up -C .
abort: rebase in progress
(use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
[255]
[20]
$ hg graft 3
abort: rebase in progress
(use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
[255]
[20]
$ hg abort
saved backup bundle to $TESTTMP/interrupted/.hg/strip-backup/3d8812cf300d-93041a90-backup.hg
......
......@@ -57,7 +57,7 @@ Try to call --continue:
$ hg rebase --continue
abort: no rebase in progress
[255]
[20]
Conflicting rebase:
......
......@@ -484,7 +484,7 @@ Retrying without in-memory merge won't lose working copy changes
transaction abort!
rollback completed
abort: uncommitted changes
[255]
[20]
$ cat a
dirty
......@@ -503,7 +503,7 @@ Retrying without in-memory merge won't lose merge state
$ hg rebase -s 2 -d 7
abort: outstanding uncommitted merge
(use 'hg commit' or 'hg merge --abort')
[255]
[20]
$ hg resolve -l
U e
......@@ -893,7 +893,7 @@ Test rebasing when we're in the middle of a rebase already
$ hg rebase -r 3 -d 1 -t:merge3
abort: rebase in progress
(use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
[255]
[20]
$ hg resolve --list
U foo
$ hg resolve --all --re-merge -t:other
......
......@@ -392,7 +392,7 @@ mangling the working directory...
$ hg rebase -s 5 -d 4 --dry-run
starting dry-run rebase; repository will not be changed
abort: uncommitted changes
[255]
[20]
$ hg diff
diff -r 2b586e70108d A
--- a/A Thu Jan 01 00:00:00 1970 +0000
......@@ -406,7 +406,7 @@ mangling the working directory...
$ echo n | hg rebase -s 5 -d 4 --confirm --config ui.interactive=True
starting in-memory rebase
abort: uncommitted changes
[255]
[20]
$ hg diff
diff -r 2b586e70108d A
--- a/A Thu Jan 01 00:00:00 1970 +0000
......@@ -417,7 +417,7 @@ mangling the working directory...
$ hg rebase -s 5 -d 4 --confirm
starting in-memory rebase
abort: uncommitted changes
[255]
[20]
$ hg diff
diff -r 2b586e70108d A
--- a/A Thu Jan 01 00:00:00 1970 +0000
......
......@@ -2058,7 +2058,7 @@ Test --stop raise errors with conflicting options:
$ hg rebase -s 3 -d 5
abort: rebase in progress
(use 'hg rebase --continue', 'hg rebase --abort', or 'hg rebase --stop')
[255]
[20]
$ hg rebase --stop --continue
abort: cannot specify both --stop and --continue
[10]
......
......@@ -500,7 +500,7 @@ Test --tool parameter:
$ hg graft --continue
abort: no graft in progress
(continue: hg rebase --continue)
[255]
[20]
$ hg rebase -c --tool internal:fail
rebasing 2:e4e3f3546619 tip "c2b"
note: not rebasing 2:e4e3f3546619 tip "c2b", its destination already has all its changes
......
......@@ -80,7 +80,7 @@ Abort pull early if working dir is not clean:
$ hg pull --rebase
abort: uncommitted changes
(cannot pull with rebase: please commit or shelve your changes first)
[255]
[20]
$ hg update --clean --quiet
Abort pull early if another operation (histedit) is in progress:
......@@ -94,7 +94,7 @@ Abort pull early if another operation (histedit) is in progress:
$ hg pull --rebase
abort: histedit in progress
(use 'hg histedit --continue' or 'hg histedit --abort')
[255]
[20]
$ hg histedit --abort --quiet
Abort pull early with pending uncommitted merge:
......@@ -117,7 +117,7 @@ Abort pull early with pending uncommitted merge:
$ hg pull --rebase
abort: outstanding uncommitted merge
(cannot pull with rebase: please commit or shelve your changes first)
[255]
[20]
$ hg update --clean --quiet
Abort pull early with unclean subrepo:
......
......@@ -132,13 +132,13 @@ resolve --all should abort when no merge in progress
$ hg resolve --all
abort: resolve command not applicable when not merging
[255]
[20]
resolve -m should abort when no merge in progress