configwizard: check for multiple version-control-tools directories (bug 1277406); r?glob draft
authorGregory Szorc <gps@mozilla.com>
Wed, 01 Jun 2016 16:41:31 -0700
changeset 8508 1c9d915ff877c141051ce30a639887dd66a69ac7
parent 8507 ffb38f765f7087fa32b60ae047e6670da98c54b5
child 8509 4523fa73ff1fa1a01d5a106613793f9b7276b484
push id918
push userbmo:gps@mozilla.com
push dateThu, 09 Jun 2016 19:23:31 +0000
reviewersglob
bugs1277406
configwizard: check for multiple version-control-tools directories (bug 1277406); r?glob MozReview-Commit-ID: JA8XH767fNI
hgext/configwizard/__init__.py
hgext/configwizard/hgsetup/wizard.py
hgext/configwizard/tests/test-multiple-vct.t
--- a/hgext/configwizard/__init__.py
+++ b/hgext/configwizard/__init__.py
@@ -203,16 +203,30 @@ try syntax and pushes it to the try serv
 to be used in concert with other tools generating try syntax so that
 they can push to try without depending on mq or other workarounds.
 
 (Relevant config option: extensions.push-to-try)
 
 Would you like to activate push-to-try (Yn)? $$ &Yes $$ &No
 '''.strip()
 
+MULTIPLE_VCT = '''
+*** WARNING ***
+
+Multiple version-control-tools repositories are referenced in your
+Mercurial config. Extensions and other code within the
+version-control-tools repository could run with inconsistent results.
+
+Please manually edit the following file to reference a single
+version-control-tools repository:
+
+    %s
+
+'''.lstrip()
+
 FILE_PERMISSIONS_WARNING = '''
 Your hgrc file is currently readable by others.
 
 Sensitive information such as your Bugzilla credentials could be
 stolen if others have access to this file/machine.
 
 Would you like to fix the file permissions (Yn) $$ &Yes $$ &No
 '''.strip()
@@ -231,16 +245,17 @@ wizardsteps = {
     'color',
     'historyediting',
     'fsmonitor',
     'wip',
     'security',
     'firefoxtree',
     'codereview',
     'pushtotry',
+    'multiplevct',
     'configchange',
     'permissions',
 }
 
 @command('configwizard', [
     ('s', 'statedir', '', _('directory to store state')),
     ], _('hg configwizard'), optionalrepo=True)
 def configwizard(ui, repo, statedir=None, **opts):
@@ -290,16 +305,19 @@ def configwizard(ui, repo, statedir=None
         _promptvctextension(ui, cw, 'firefoxtree', FIREFOXTREE_INFO)
 
     if 'codereview' in runsteps:
         _checkcodereview(ui, cw)
 
     if 'pushtotry' in runsteps:
         _promptvctextension(ui, cw, 'push-to-try', PUSHTOTRY_INFO)
 
+    if 'multiplevct' in runsteps:
+        _checkmultiplevct(ui, cw)
+
     if 'configchange' in runsteps:
         _handleconfigchange(ui, cw)
 
     if 'permissions' in runsteps:
         _checkpermissions(ui, cw)
 
     return 0
 
@@ -575,16 +593,35 @@ def _checkcodereview(ui, cw):
     for c in ('password', 'userid', 'cookie'):
         try:
             del cw.c['bugzilla'][c]
         except KeyError:
             pass
 
     # TODO configure mozilla.ircnick and the "review" path
 
+
+def _checkmultiplevct(ui, cw):
+    # References to multiple version-control-tools checkouts can confuse
+    # version-control-tools since various Mercurial extensions resolve
+    # dependencies via __file__. Files from different revisions could lead
+    # to unexpected environments and break things.
+    seenvct = set()
+    for k, v in ui.configitems('extensions'):
+        if 'version-control-tools' not in v:
+            continue
+
+        i = v.index('version-control-tools')
+        vct = v[0:i + len('version-control-tools')]
+        seenvct.add(os.path.realpath(os.path.expanduser(vct)))
+
+    if len(seenvct) > 1:
+        ui.write(MULTIPLE_VCT % cw.path)
+
+
 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
@@ -26,29 +26,16 @@ from .config import (
     ParseException,
 )
 
 FINISHED = '''
 Your Mercurial should now be properly configured and recommended extensions
 should be up to date!
 '''.strip()
 
-MULTIPLE_VCT = '''
-*** WARNING ***
-
-Multiple version-control-tools repositories are referenced in your
-Mercurial config. Extensions and other code within the
-version-control-tools repository could run with inconsistent results.
-
-Please manually edit the following file to reference a single
-version-control-tools repository:
-
-    %s
-'''.lstrip()
-
 
 class MercurialSetupWizard(object):
     """Command-line wizard to help users configure Mercurial."""
 
     def __init__(self, state_dir):
         # We use normpath since Mercurial expects the hgrc to use native path
         # separators, but state_dir uses unix style paths even on Windows.
         self.state_dir = os.path.normpath(state_dir)
@@ -74,26 +61,11 @@ class MercurialSetupWizard(object):
         for ext in {'bzexport', 'qimportbz', 'mqext'}:
             path = os.path.join(self.ext_dir, ext)
             if os.path.exists(path):
                 if self._prompt_yn('Would you like to remove the old and no '
                     'longer referenced repository at %s' % path):
                     print('Cleaning up old repository: %s' % path)
                     shutil.rmtree(path)
 
-        # References to multiple version-control-tools checkouts can confuse
-        # version-control-tools, since various Mercurial extensions resolve
-        # dependencies via __file__ and repos could reference another copy.
-        seen_vct = set()
-        for k, v in c.config.get('extensions', {}).items():
-            if 'version-control-tools' not in v:
-                continue
-
-            i = v.index('version-control-tools')
-            vct = v[0:i + len('version-control-tools')]
-            seen_vct.add(os.path.realpath(os.path.expanduser(vct)))
-
-        if len(seen_vct) > 1:
-            print(MULTIPLE_VCT % c.config_path)
-
         print(FINISHED)
         return 0
 
new file mode 100644
--- /dev/null
+++ b/hgext/configwizard/tests/test-multiple-vct.t
@@ -0,0 +1,24 @@
+  $ . $TESTDIR/hgext/configwizard/tests/helpers.sh
+
+  $ mkdir -p version-control-tools/hgext/firefoxtree
+  $ touch version-control-tools/hgext/firefoxtree/__init__.py
+
+  $ hg --config extensions.firefoxtree=$TESTTMP/version-control-tools/hgext/firefoxtree --config configwizard.steps=multiplevct 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>
+  *** WARNING ***
+  
+  Multiple version-control-tools repositories are referenced in your
+  Mercurial config. Extensions and other code within the
+  version-control-tools repository could run with inconsistent results.
+  
+  Please manually edit the following file to reference a single
+  version-control-tools repository:
+  
+      $TESTTMP/.hgrc
+