configwizard: prompt for enabling history editing extensions (bug 1277406); r=glob draft
authorGregory Szorc <gps@mozilla.com>
Wed, 01 Jun 2016 13:56:53 -0700
changeset 8496 de3e8012ca95bee652eb035da24d2ff74f58931d
parent 8495 5f699400f28ab997810d583e4a0db23eda3c095c
child 8497 57cf6aa564b83f61765505a3d18ec03dedb7cd0a
push id918
push userbmo:gps@mozilla.com
push dateThu, 09 Jun 2016 19:23:31 +0000
reviewersglob
bugs1277406
configwizard: prompt for enabling history editing extensions (bug 1277406); r=glob Before, we prompted separately for both histedit and rebase. Let's make it simpler by just having one prompt and enabling both. MozReview-Commit-ID: 799M1NQ1GO
hgext/configwizard/__init__.py
hgext/configwizard/hgsetup/wizard.py
hgext/configwizard/tests/test-historyediting.t
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -75,16 +75,17 @@ buglink = 'https://bugzilla.mozilla.org/
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
 wizardsteps = {
     'hgversion',
     'username',
     'diff',
     'color',
+    'historyediting',
     'configchange',
 }
 
 @command('configwizard', [
     ('s', 'statedir', '', _('directory to store state')),
     ], _('hg configwizard'), optionalrepo=True)
 def configwizard(ui, repo, statedir=None, **opts):
     """Ensure your Mercurial configuration is up to date."""
@@ -112,16 +113,19 @@ def configwizard(ui, repo, statedir=None
         _checkusername(ui, cw)
 
     if 'diff' in runsteps:
         _checkdiffsettings(ui, cw)
 
     if 'color' in runsteps:
         _promptnativeextension(ui, cw, 'color', 'Enable color output to your terminal')
 
+    if 'historyediting' in runsteps:
+        _checkhistoryediting(ui, cw)
+
     if 'configchange' in runsteps:
         return _handleconfigchange(ui, cw)
 
     return 0
 
 
 def _checkhgversion(ui, hgversion):
     if hgversion >= OLDEST_NON_LEGACY_VERSION:
@@ -203,16 +207,30 @@ def _promptnativeextension(ui, cw, ext, 
 
     if not ui.promptchoice('%s (Yn) $$ &Yes $$ &No' % msg):
         if 'extensions' not in cw.c:
             cw.c['extensions'] = {}
 
         cw.c['extensions'][ext] = ''
 
 
+def _checkhistoryediting(ui, cw):
+    if all(ui.hasconfig('extensions', e) for e in ('histedit', 'rebase')):
+        return
+
+    if ui.promptchoice('Enable history rewriting commands (Yn)? $$ &Yes $$ &No'):
+        return
+
+    if 'extensions' not in cw.c:
+        cw.c['extensions'] = {}
+
+    cw.c['extensions']['histedit'] = ''
+    cw.c['extensions']['rebase'] = ''
+
+
 def _handleconfigchange(ui, cw):
     # Obtain the old and new content so we can show a diff.
     newbuf = io.BytesIO()
     cw.write(newbuf)
     newbuf.seek(0)
     newlines = [l.rstrip() for l in newbuf.readlines()]
     oldlines = []
     if os.path.exists(cw.path):
--- a/hgext/configwizard/hgsetup/wizard.py
+++ b/hgext/configwizard/hgsetup/wizard.py
@@ -244,28 +244,16 @@ class MercurialSetupWizard(object):
 
         hg_version = get_hg_version(hg)
 
         # Progress is built into core and enabled by default in Mercurial 3.5.
         if hg_version < LooseVersion('3.5'):
             self.prompt_native_extension(c, 'progress',
                 'Would you like to see progress bars during Mercurial operations')
 
-        self.prompt_native_extension(c, 'color',
-            'Would you like Mercurial to colorize output to your terminal')
-
-        self.prompt_native_extension(c, 'rebase',
-            'Would you like to enable the rebase extension to allow you to move'
-            ' changesets around (which can help maintain a linear history)')
-
-        self.prompt_native_extension(c, 'histedit',
-            'Would you like to enable the histedit extension to allow history '
-            'rewriting via the "histedit" command (similar to '
-            '`git rebase -i`)')
-
         # hgwatchman is provided by MozillaBuild and we don't yet support
         # Linux/BSD.
         if ('hgwatchman' not in c.extensions
             and sys.platform.startswith('darwin')
             and hg_version >= HGWATCHMAN_MINIMUM_VERSION
             and self._prompt_yn(HGWATCHMAN_INFO)):
             # Unlike other extensions, we need to run an installer
             # to compile a Python C extension.
new file mode 100644
--- /dev/null
+++ b/hgext/configwizard/tests/test-historyediting.t
@@ -0,0 +1,55 @@
+  $ . $TESTDIR/hgext/configwizard/tests/helpers.sh
+
+Rejecting history editing doesn't enable extensions
+
+  $ hg --config ui.interactive=true --config configwizard.steps=historyediting,configchange configwizard << EOF
+  > 
+  > n
+  > EOF
+  This wizard will guide you through configuring Mercurial for an optimal
+  experience contributing to Mozilla projects.
+  
+  The wizard makes no changes without your permission.
+  
+  To begin, press the enter/return key.
+   <RETURN>
+  Enable history rewriting commands (Yn)?  n
+
+
+No prompt if extensions already enabled
+
+  $ hg --config configwizard.steps=historyediting --config extensions.histedit= --config extensions.rebase= configwizard
+  This wizard will guide you through configuring Mercurial for an optimal
+  experience contributing to Mozilla projects.
+  
+  The wizard makes no changes without your permission.
+  
+  To begin, press the enter/return key.
+   <RETURN>
+
+histedit and rebase enabled when appropriate
+
+  $ hg --config configwizard.steps=historyediting,configchange configwizard
+  This wizard will guide you through configuring Mercurial for an optimal
+  experience contributing to Mozilla projects.
+  
+  The wizard makes no changes without your permission.
+  
+  To begin, press the enter/return key.
+   <RETURN>
+  Enable history rewriting commands (Yn)?  y
+  Your config file needs updating.
+  Would you like to see a diff of the changes first (Yn)?  y
+  --- hgrc.old
+  +++ hgrc.new
+  @@ -0,0 +1,3 @@
+  +[extensions]
+  +histedit =
+  +rebase =
+  
+  Write changes to hgrc file (Yn)?  y
+
+  $ cat .hgrc
+  [extensions]
+  histedit = 
+  rebase =