martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  `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).

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D12390

AFFECTED FILES
  hgext/uncommit.py
  tests/test-unamend.t

CHANGE DETAILS

diff --git a/tests/test-unamend.t b/tests/test-unamend.t
--- a/tests/test-unamend.t
+++ b/tests/test-unamend.t
@@ -39,8 +39,23 @@
 Trying to unamend when there was no amend done
 
   $ hg unamend
+  abort: working copy parent was not created by 'hg amend' or 'hg unamend'
+  [10]
+  $ echo "bar" >> h
+
+Trying to unamend when the obsmarker is missing
+
+  $ hg amend
+  $ hg debugobsolete --delete 0
+  deleted 1 obsolescence markers
+  $ hg unamend
   abort: changeset must have one predecessor, found 0 predecessors
   [10]
+  $ hg strip tip --config extensions.strip=
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  saved backup bundle to 
$TESTTMP/repo/.hg/strip-backup/c9fa1a715c1b-06e5c233-backup.hg
+  $ hg up tip
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
 Unamend on clean wdir and tip
 
diff --git a/hgext/uncommit.py b/hgext/uncommit.py
--- a/hgext/uncommit.py
+++ b/hgext/uncommit.py
@@ -276,6 +276,15 @@
         if len(curctx.parents()) > 1:
             raise error.InputError(_(b"cannot unamend merge changeset"))
 
+        expected_keys = (b'amend_source', b'unamend_source')
+        if not any(key in curctx.extra() for key in expected_keys):
+            raise error.InputError(
+                _(
+                    b"working copy parent was not created by 'hg amend' or "
+                    b"'hg unamend'"
+                )
+            )
+
         # identify the commit to which to unamend
         markers = list(predecessormarkers(curctx))
         if len(markers) != 1:



To: martinvonz, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to