configwizard: prompt to enable color extension (bug 1277406); r=glob draft
authorGregory Szorc <gps@mozilla.com>
Wed, 01 Jun 2016 13:51:13 -0700
changeset 8495 5f699400f28ab997810d583e4a0db23eda3c095c
parent 8494 12a4c9f1a7b69ce88e2595536f3fa846a6fd51c4
child 8496 de3e8012ca95bee652eb035da24d2ff74f58931d
push id918
push userbmo:gps@mozilla.com
push dateThu, 09 Jun 2016 19:23:31 +0000
reviewersglob
bugs1277406
configwizard: prompt to enable color extension (bug 1277406); r=glob MozReview-Commit-ID: LIsIbJ89LCe
hgext/configwizard/__init__.py
hgext/configwizard/tests/test-color.t
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -74,16 +74,17 @@ buglink = 'https://bugzilla.mozilla.org/
 
 cmdtable = {}
 command = cmdutil.command(cmdtable)
 
 wizardsteps = {
     'hgversion',
     'username',
     'diff',
+    'color',
     '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."""
@@ -108,16 +109,19 @@ def configwizard(ui, repo, statedir=None
             return 1
 
     if 'username' in runsteps:
         _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 'configchange' in runsteps:
         return _handleconfigchange(ui, cw)
 
     return 0
 
 
 def _checkhgversion(ui, hgversion):
     if hgversion >= OLDEST_NON_LEGACY_VERSION:
@@ -188,16 +192,27 @@ def _checkdiffsettings(ui, cw):
     if not uipromptchoice(ui, BAD_DIFF_SETTINGS):
         if 'diff' not in cw.c:
             cw.c['diff'] = {}
 
         cw.c['diff']['git'] = 'true'
         cw.c['diff']['showfunc'] = 'true'
 
 
+def _promptnativeextension(ui, cw, ext, msg):
+    if ui.hasconfig('extensions', ext):
+        return
+
+    if not ui.promptchoice('%s (Yn) $$ &Yes $$ &No' % msg):
+        if 'extensions' not in cw.c:
+            cw.c['extensions'] = {}
+
+        cw.c['extensions'][ext] = ''
+
+
 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):
new file mode 100644
--- /dev/null
+++ b/hgext/configwizard/tests/test-color.t
@@ -0,0 +1,52 @@
+  $ . $TESTDIR/hgext/configwizard/tests/helpers.sh
+
+Rejecting color doesn't enable it
+
+  $ hg --config ui.interactive=true --config configwizard.steps=color,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 color output to your terminal (Yn)  n
+
+
+No prompt if color already enabled
+
+  $ hg --config configwizard.steps=color --config extensions.color= 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>
+
+color extension enabled if no input
+
+  $ hg --config configwizard.steps=color,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 color output to your terminal (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,2 @@
+  +[extensions]
+  +color =
+  
+  Write changes to hgrc file (Yn)?  y
+  $ cat .hgrc
+  [extensions]
+  color =