configwizard: prompt to enable color extension (
bug 1277406); r=glob
MozReview-Commit-ID: LIsIbJ89LCe
--- 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 =