1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this,
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 from __future__
import absolute_import
, print_function
, unicode_literals
10 from mach
.decorators
import (
18 class VersionControlCommands(object):
19 def __init__(self
, context
):
20 self
._context
= context
22 @Command('mercurial-setup', category
='devenv',
23 description
='Help configure Mercurial for optimal development.')
24 @CommandArgument('-u', '--update-only', action
='store_true',
25 help='Only update recommended extensions, don\'t run the wizard.')
26 def mercurial_setup(self
, update_only
=False):
27 """Ensure Mercurial is optimally configured.
29 This command will inspect your Mercurial configuration and
30 guide you through an interactive wizard helping you configure
31 Mercurial for optimal use on Mozilla projects.
33 User choice is respected: no changes are made without explicit
34 confirmation from you.
36 If "--update-only" is used, the interactive wizard is disabled
37 and this command only ensures that remote repositories providing
38 Mercurial extensions are up to date.
40 sys
.path
.append(os
.path
.dirname(__file__
))
42 config_paths
= ['~/.hgrc']
43 if sys
.platform
in ('win32', 'cygwin'):
44 config_paths
.insert(0, '~/mercurial.ini')
45 config_paths
= map(os
.path
.expanduser
, config_paths
)
47 # Touch a file so we can periodically prompt to update extensions.
49 # We put this before main command logic because the command can
50 # persistently fail and we want people to get credit for the
51 # intention, not whether the command is bug free.
52 state_dir
= os
.path
.join(self
._context
.state_dir
, 'mercurial')
53 if not os
.path
.isdir(state_dir
):
54 os
.makedirs(state_dir
)
56 state_path
= os
.path
.join(state_dir
, 'setup.lastcheck')
58 with
open(state_path
, 'a'):
59 os
.utime(state_path
, None)
62 from hgsetup
.update
import MercurialUpdater
63 updater
= MercurialUpdater(self
._context
.state_dir
)
64 result
= updater
.update_all()
66 from hgsetup
.wizard
import MercurialSetupWizard
67 wizard
= MercurialSetupWizard(self
._context
.state_dir
)
68 result
= wizard
.run(map(os
.path
.expanduser
, config_paths
))
71 print('(despite the failure, mach will not nag you to run '
72 '`mach mercurial-setup`)')