comparison hgext/uncommit.py @ 48979:9120c0cd935c stable

unamend: abort if commit was not created by `hg [un]amend` `hg unamend` can currently undo any kind of rewrite, as long as it has an obsmarker. However, that has quite unexpected results if you run it after e.g. `hg rebase` (expecting it to behave like a generic `hg undo` command), because it updates to the predecessor and leaves the old changes in the working copy. I think it's better to allow `hg unamend` only after `hg amend` (and after `hg unamend` because that's documented as being supported). Differential Revision: https://phab.mercurial-scm.org/D12390
author Martin von Zweigbergk <martinvonz@google.com>
date Mon, 21 Mar 2022 14:21:10 -0700
parents 4f01821fa0ec
children 533820f5b997
comparison
equal deleted inserted replaced
48977:bd752712ccaf 48979:9120c0cd935c
274 274
275 rewriteutil.precheck(repo, [curctx.rev()], b'unamend') 275 rewriteutil.precheck(repo, [curctx.rev()], b'unamend')
276 if len(curctx.parents()) > 1: 276 if len(curctx.parents()) > 1:
277 raise error.InputError(_(b"cannot unamend merge changeset")) 277 raise error.InputError(_(b"cannot unamend merge changeset"))
278 278
279 expected_keys = (b'amend_source', b'unamend_source')
280 if not any(key in curctx.extra() for key in expected_keys):
281 raise error.InputError(
282 _(
283 b"working copy parent was not created by 'hg amend' or "
284 b"'hg unamend'"
285 )
286 )
287
279 # identify the commit to which to unamend 288 # identify the commit to which to unamend
280 markers = list(predecessormarkers(curctx)) 289 markers = list(predecessormarkers(curctx))
281 if len(markers) != 1: 290 if len(markers) != 1:
282 e = _(b"changeset must have one predecessor, found %i predecessors") 291 e = _(b"changeset must have one predecessor, found %i predecessors")
283 raise error.InputError(e % len(markers)) 292 raise error.InputError(e % len(markers))