rollback: add a config knob for entirely disabling the command
authorAugie Fackler <augie@google.com>
Tue, 03 May 2016 16:33:25 -0400
changeset 29086 fe50341de1ff
parent 29085 df838803c1d4
child 29087 ad1bdea43965
rollback: add a config knob for entirely disabling the command This is of pretty high value for organizations that used to use p4 (as an example), since `p4 rollback` is what we call `hg backout`.
mercurial/commands.py
tests/test-rollback.t
--- a/mercurial/commands.py	Tue May 03 09:49:54 2016 -0700
+++ b/mercurial/commands.py	Tue May 03 16:33:25 2016 -0400
@@ -6383,6 +6383,11 @@
       commit transaction if it isn't checked out. Use --force to
       override this protection.
 
+      The rollback command can be entirely disabled by setting the
+      ``ui.rollback`` configuration setting to false. If you're here
+      because you want to use rollback and it's disabled, you can
+      re-enable the command by setting ``ui.rollback`` to true.
+
     This command is not intended for use on public repositories. Once
     changes are visible for pull by other users, rolling a transaction
     back locally is ineffective (someone else may already have pulled
@@ -6392,6 +6397,9 @@
 
     Returns 0 on success, 1 if no rollback data is available.
     """
+    if not ui.configbool('ui', 'rollback', True):
+        raise error.Abort(_('rollback is disabled because it is unsafe'),
+                          hint=('see `hg help -v rollback` for information'))
     return repo.rollback(dryrun=opts.get('dry_run'),
                          force=opts.get('force'))
 
--- a/tests/test-rollback.t	Tue May 03 09:49:54 2016 -0700
+++ b/tests/test-rollback.t	Tue May 03 16:33:25 2016 -0400
@@ -196,3 +196,15 @@
   checking files
   1 files, 2 changesets, 2 total revisions
 
+rollback disabled by config
+  $ cat >> $HGRCPATH <<EOF
+  > [ui]
+  > rollback = false
+  > EOF
+  $ echo narf >> pinky-sayings.txt
+  $ hg add pinky-sayings.txt
+  $ hg ci -m 'First one.'
+  $ hg rollback
+  abort: rollback is disabled because it is unsafe
+  (see `hg help -v rollback` for information)
+  [255]