D5940: uncommit: add --allowdirtywcopy when possibly hiding data (issue5977)

navaneeth.suresh (Navaneeth Suresh) phabricator at mercurial-scm.org
Fri Feb 15 19:08:33 UTC 2019


navaneeth.suresh updated this revision to Diff 14100.
navaneeth.suresh edited the summary of this revision.
navaneeth.suresh retitled this revision from "uncommit: add -f/--force when possibly hiding data (issue5977)" to "uncommit: add --allowdirtywcopy when possibly hiding data (issue5977)".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5940?vs=14096&id=14100

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

AFFECTED FILES
  hgext/uncommit.py
  mercurial/rewriteutil.py
  tests/test-uncommit.t

CHANGE DETAILS

diff --git a/tests/test-uncommit.t b/tests/test-uncommit.t
--- a/tests/test-uncommit.t
+++ b/tests/test-uncommit.t
@@ -35,6 +35,7 @@
   options ([+] can be repeated):
   
       --keep                allow an empty commit after uncommiting
+      --allowdirtywcopy     allow uncommit with outstanding changes
    -I --include PATTERN [+] include names matching the given patterns
    -X --exclude PATTERN [+] exclude names matching the given patterns
   
@@ -156,8 +157,12 @@
   M files
   $ hg uncommit
   abort: uncommitted changes
+  (use --allowdirtywcopy to uncommit)
   [255]
   $ hg uncommit files
+  abort: uncommitted changes
+  (use --allowdirtywcopy to uncommit)
+  [255]
   $ cat files
   abcde
   foo
@@ -168,6 +173,7 @@
   $ echo "bar" >> files
   $ hg uncommit
   abort: uncommitted changes
+  (use --allowdirtywcopy to uncommit)
   [255]
   $ hg uncommit --config experimental.uncommitondirtywdir=True
   $ hg commit -m "files abcde + foo"
@@ -191,16 +197,16 @@
   +abc
   
   $ hg bookmark
-     foo                       10:48e5bd7cd583
+     foo                       9:48e5bd7cd583
   $ hg uncommit
   3 new orphan changesets
   $ hg status
   M files
   A file-abc
   $ hg heads -T '{rev}:{node} {desc}'
-  10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo (no-eol)
+  9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo (no-eol)
   $ hg bookmark
-     foo                       10:48e5bd7cd583
+     foo                       9:48e5bd7cd583
   $ hg commit -m 'new abc'
   created new head
 
@@ -222,38 +228,36 @@
   +ab
   
   $ hg bookmark
-     foo                       10:48e5bd7cd583
+     foo                       9:48e5bd7cd583
   $ hg uncommit file-ab
   1 new orphan changesets
   $ hg status
   A file-ab
 
   $ hg heads -T '{rev}:{node} {desc}\n'
-  12:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
-  11:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
-  10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
+  11:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
+  10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
+  9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
 
   $ hg bookmark
-     foo                       10:48e5bd7cd583
+     foo                       9:48e5bd7cd583
   $ hg commit -m 'update ab'
   $ hg status
   $ hg heads -T '{rev}:{node} {desc}\n'
-  13:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
-  11:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
-  10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
+  12:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
+  10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
+  9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
 
   $ hg log -G -T '{rev}:{node} {desc}' --hidden
-  @  13:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
+  @  12:f21039c59242b085491bb58f591afc4ed1c04c09 update ab
   |
-  o  12:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
+  o  11:8eb87968f2edb7f27f27fe676316e179de65fff6 added file-ab
   |
-  | *  11:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
+  | *  10:5dc89ca4486f8a88716c5797fa9f498d13d7c2e1 new abc
   | |
-  | | *  10:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
+  | | *  9:48e5bd7cd583eb24164ef8b89185819c84c96ed7 files abcde + foo
   | | |
-  | | | x  9:8a6b58c173ca6a2e3745d8bd86698718d664bc6c files abcde + foo
-  | | |/
-  | | | x  8:39ad452c7f684a55d161c574340c5766c4569278 update files for abcde
+  | | | x  8:84beeba0ac30e19521c036e4d2dd3a5fa02586ff files abcde + foo
   | | |/
   | | | x  7:0977fa602c2fd7d8427ed4e7ee15ea13b84c9173 update files for abcde
   | | |/
@@ -275,22 +279,22 @@
 
   $ hg uncommit
   $ hg phase -r .
-  12: draft
+  11: draft
   $ hg commit -m 'update ab again'
 
 Phase is preserved
 
   $ hg uncommit --keep --config phases.new-commit=secret
   $ hg phase -r .
-  15: draft
+  14: draft
   $ hg commit --amend -m 'update ab again'
 
 Uncommit with public parent
 
   $ hg phase -p "::.^"
   $ hg uncommit
   $ hg phase -r .
-  12: public
+  11: public
 
 Partial uncommit with public parent
 
@@ -301,9 +305,9 @@
   $ hg status
   A xyz
   $ hg phase -r .
-  18: draft
+  17: draft
   $ hg phase -r ".^"
-  12: public
+  11: public
 
 Uncommit leaving an empty changeset
 
@@ -368,6 +372,7 @@
 
   $ hg uncommit
   abort: outstanding uncommitted merge
+  (use --allowdirtywcopy to uncommit)
   [255]
 
   $ hg uncommit --config experimental.uncommitondirtywdir=True
@@ -379,7 +384,7 @@
   $ hg commit -m 'merge a and b'
 
   $ hg uncommit
-  abort: cannot uncommit merge changeset
+  abort: cannot uncommit merge changesets
   [255]
 
   $ hg status
@@ -398,3 +403,35 @@
   |/
   o  0:ea4e33293d4d274a2ba73150733c2612231f398c a 1
   
+  $ cd ..
+
+Uncommit should require -f/--force when possibly hiding data
+
+  $ hg init issue5977
+  $ cd issue5977
+  $ echo 'super critical info!' > a
+  $ hg ci -Am 'add a'
+  adding a
+  $ echo 'foo' > a
+  $ hg unc a
+  abort: uncommitted changes
+  (use --allowdirtywcopy to uncommit)
+  [255]
+  $ cat a
+  foo
+  $ hg log
+  changeset:   0:e37b99831f6e
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add a
+  
+  $ hg unc --allowdirtywcopy a
+  $ hg log
+  changeset:   1:656ba143d384
+  tag:         tip
+  parent:      -1:000000000000
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add a
+  
diff --git a/mercurial/rewriteutil.py b/mercurial/rewriteutil.py
--- a/mercurial/rewriteutil.py
+++ b/mercurial/rewriteutil.py
@@ -16,9 +16,10 @@
     revset,
 )
 
-def precheck(repo, revs, action='rewrite'):
+def precheck(repo, revs, action='rewrite', merge=False):
     """check if revs can be rewritten
     action is used to control the error message.
+    action is used to true the reject merges.
 
     Make sure this function is called after taking the lock.
     """
@@ -39,6 +40,9 @@
     newunstable = disallowednewunstable(repo, revs)
     if newunstable:
         raise error.Abort(_("cannot %s changeset with children") % action)
+    if merge and any(repo[r].p2() for r in revs):
+        msg = _("cannot %s merge changesets") % (action,)
+        raise error.Abort(msg)
 
 def disallowednewunstable(repo, revs):
     """Checks whether editing the revs will create new unstable changesets and
diff --git a/hgext/uncommit.py b/hgext/uncommit.py
--- a/hgext/uncommit.py
+++ b/hgext/uncommit.py
@@ -137,6 +137,8 @@
 
 @command('uncommit',
     [('', 'keep', False, _('allow an empty commit after uncommiting')),
+     ('', 'allowdirtywcopy', False, _('allow uncommit with '
+                                               'outstanding changes')),
     ] + commands.walkopts,
     _('[OPTION]... [FILE]...'),
     helpcategory=command.CATEGORY_CHANGE_MANAGEMENT)
@@ -155,16 +157,19 @@
 
     with repo.wlock(), repo.lock():
 
-        if not pats and not repo.ui.configbool('experimental',
-                                               'uncommitondirtywdir'):
-            cmdutil.bailifchanged(repo)
+        if (not repo.ui.configbool('experimental', 'uncommitondirtywdir')
+            and not opts.get('allowdirtywcopy')):
+            cmdutil.bailifchanged(repo, hint=_('use '
+                                  '--allowdirtywcopy to uncommit'))
         old = repo['.']
-        rewriteutil.precheck(repo, [old.rev()], 'uncommit')
-        if len(old.parents()) > 1:
-            raise error.Abort(_("cannot uncommit merge changeset"))
+        rewriteutil.precheck(repo, [old.rev()], 'uncommit', merge=True)
 
+        match = scmutil.match(old, pats, opts)
+        # explicitly check for a merge, so it cannot be overridden
+
+        if old.p2():
+            raise error.Abort(_("outstanding uncommitted merge"))
         with repo.transaction('uncommit'):
-            match = scmutil.match(old, pats, opts)
             keepcommit = opts.get('keep') or pats
             newid = _commitfiltered(repo, old, match, keepcommit)
             if newid is None:



To: navaneeth.suresh, #hg-reviewers
Cc: martinvonz, pulkit, mercurial-devel


More information about the Mercurial-devel mailing list