Commit b5154c4d authored by Gregory Szorc's avatar Gregory Szorc
Browse files

Bug 1184229 - Detect multiple version-control-tools repos in Mercurial config; r=smacleod

Having multiple version-control-tools repositories references in your
hgrc could lead to one repository importing code from another, depending
on how sys.path modification works from version-control-tools
repositories. Detect it and issue a warning.

--HG--
extra : commitid : 2rfQARjGfu9
extra : rebase_source : 01d221cdc4b462cb52041d1d18f121e09b23125c
extra : amend_source : bac3fd876d6c8f0a3a94f4ae25950f5971dcb869
parent 555a3164
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -213,6 +213,20 @@ Sensitive information such as your Bugzilla credentials could be
stolen if others have access to this file/machine.
'''.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."""

@@ -404,6 +418,23 @@ class MercurialSetupWizard(object):

        c.add_mozilla_host_fingerprints()

        # 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)

        # At this point the config should be finalized.

        b = StringIO()
        c.write(b)
        new_lines = [line.rstrip() for line in b.getvalue().splitlines()]