changeset 20782:13fcb9ca9ccc

config: add --global and --local flags These start an editor on the system-wide or repository-level config files.
author Matt Mackall <mpm@selenic.com>
date Tue, 18 Mar 2014 18:49:30 -0500
parents 8ecfa225bd16
children 43054dc84abd
files mercurial/commands.py tests/test-completion.t
diffstat 2 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Tue Mar 18 17:56:27 2014 -0500
+++ b/mercurial/commands.py	Tue Mar 18 18:49:30 2014 -0500
@@ -1462,8 +1462,10 @@
 
 @command('config|showconfig|debugconfig',
     [('u', 'untrusted', None, _('show untrusted configuration options')),
-     ('e', 'edit', None, _('start editor'))],
-    _('[-u] [NAME]...'))
+     ('e', 'edit', None, _('edit user config')),
+     ('l', 'local', None, _('edit repository config')),
+     ('g', 'global', None, _('edit global config'))],
+      _('[-u] [NAME]...'))
 def config(ui, repo, *values, **opts):
     """show combined config settings from all hgrc files
 
@@ -1481,8 +1483,19 @@
     Returns 0 on success.
     """
 
-    if opts.get('edit'):
-        paths = scmutil.userrcpath()
+    if opts.get('edit') or opts.get('local') or opts.get('global'):
+        if opts.get('local') and opts.get('global'):
+            raise util.Abort(_("can't use --local and --global together"))
+
+        if opts.get('local'):
+            if not repo:
+                raise util.Abort(_("can't use --local outside a repository"))
+            paths = [repo.join('hgrc')]
+        elif opts.get('global'):
+            paths = scmutil.systemrcpath()
+        else:
+            paths = scmutil.userrcpath()
+
         for f in paths:
             if os.path.exists(f):
                 break
--- a/tests/test-completion.t	Tue Mar 18 17:56:27 2014 -0500
+++ b/tests/test-completion.t	Tue Mar 18 18:49:30 2014 -0500
@@ -222,7 +222,7 @@
   branches: active, closed
   bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure
   cat: output, rev, decode, include, exclude
-  config: untrusted, edit
+  config: untrusted, edit, local, global
   copy: after, force, include, exclude, dry-run
   debugancestor: 
   debugbuilddag: mergeable-file, overwritten-file, new-file