histedit: check first changeset for verb "roll" or "fold" (issue5498)
authorAndré Klitzing <aklitzing@gmail.com>
Fri, 11 Aug 2017 15:20:41 +0200
changeset 33783 c26a76e1af36
parent 33782 f5fc54e7e467
child 33784 dcdc17551653
histedit: check first changeset for verb "roll" or "fold" (issue5498) If someone changes "pick" to "roll" or "fold" for the first changeset in a histedit rule Mercurial could remove a wrong changeset if the phase is non-public. roll or fold for the first changeset should be invalid.
hgext/histedit.py
tests/test-histedit-edit.t
tests/test-histedit-fold.t
--- a/hgext/histedit.py	Mon Jul 31 23:13:47 2017 +0900
+++ b/hgext/histedit.py	Fri Aug 11 15:20:41 2017 +0200
@@ -1417,6 +1417,11 @@
     expected = set(c.node() for c in ctxs)
     seen = set()
     prev = None
+
+    if actions and actions[0].verb in ['roll', 'fold']:
+        raise error.ParseError(_('first changeset cannot use verb "%s"') %
+                               actions[0].verb)
+
     for action in actions:
         action.verify(prev, expected, seen)
         prev = action
--- a/tests/test-histedit-edit.t	Mon Jul 31 23:13:47 2017 +0900
+++ b/tests/test-histedit-edit.t	Fri Aug 11 15:20:41 2017 +0200
@@ -460,7 +460,7 @@
   > EOF
   $ HGEDITOR="sh ../edit.sh" hg histedit 2
   warning: histedit rules saved to: .hg/histedit-last-edit.txt
-  hg: parse error: cannot fold into public change 18aa70c8ad22
+  hg: parse error: first changeset cannot use verb "fold"
   [255]
   $ cat .hg/histedit-last-edit.txt
   fold 0012be4a27ea 2 extend a
--- a/tests/test-histedit-fold.t	Mon Jul 31 23:13:47 2017 +0900
+++ b/tests/test-histedit-fold.t	Fri Aug 11 15:20:41 2017 +0200
@@ -541,3 +541,36 @@
   END
 
   $ cd ..
+
+Test rolling into a commit with multiple children (issue5498)
+
+  $ hg init roll
+  $ cd roll
+  $ echo a > a
+  $ hg commit -qAm aa
+  $ echo b > b
+  $ hg commit -qAm bb
+  $ hg up -q ".^"
+  $ echo c > c
+  $ hg commit -qAm cc
+  $ hg log -G -T '{node|short} {desc}'
+  @  5db65b93a12b cc
+  |
+  | o  301d76bdc3ae bb
+  |/
+  o  8f0162e483d0 aa
+  
+
+  $ hg histedit . --commands - << EOF
+  > r 5db65b93a12b
+  > EOF
+  hg: parse error: first changeset cannot use verb "roll"
+  [255]
+  $ hg log -G -T '{node|short} {desc}'
+  @  5db65b93a12b cc
+  |
+  | o  301d76bdc3ae bb
+  |/
+  o  8f0162e483d0 aa
+  
+