[PATCH] config: give more fine-tuned sample hgrcs to this command

Jordi Gutiérrez Hermoso jordigh at octave.org
Wed Aug 13 16:14:52 CDT 2014


# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh at octave.org>
# Date 1407963948 14400
#      Wed Aug 13 17:05:48 2014 -0400
# Node ID f9690691301dd804ccc03d0787112c3e18cb9226
# Parent  e125a4ec265f9207667e82a62754dfd96f17c0a4
config: give more fine-tuned sample hgrcs to this command

The hgrc for user config is typically different from the hgrc at the
system-wide or repository level. This patch provides different sample
hgrcs for each level. Sometimes when copying repos around, the copy or
the original don't have a default path yet, so at least for `hg config
-l`, this ought to provide a more reasonable default and suggestions
of what typically goes there.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1520,10 +1520,9 @@ def config(ui, repo, *values, **opts):
             if os.path.exists(f):
                 break
         else:
-            f = paths[0]
-            fp = open(f, "w")
-            fp.write(
-                '# example config (see "hg help config" for more info)\n'
+            samplehgrcs = {
+                'user':
+                '# example user config (see "hg help config" for more info)\n'
                 '\n'
                 '[ui]\n'
                 '# name and email, e.g.\n'
@@ -1535,7 +1534,41 @@ def config(ui, repo, *values, **opts):
                 '# (see "hg help extensions" for more info)\n'
                 '# pager =\n'
                 '# progress =\n'
-                '# color =\n')
+                '# color =\n',
+
+                'local':
+                '# example repository config (see "hg help config" for '
+                    'more info)\n'
+                '\n'
+                '[paths]\n'
+                '# Path aliases to other clones of this repo in external '
+                     'URLs or filesystem paths,\n'
+                '\n'
+                '# default = http://example.com/hg/example-repo\n'
+                '# myfork  = ssh://jdoe@example.net/hg/jdoes-fork\n'
+                '# myclone = /home/jdoe/jdoes-clone\n',
+
+                'global':
+                '# example system-wide hg config (see "hg help config" for '
+                    'more info)\n'
+                '\n'
+                '[extensions]\n'
+                '# Uncomment these lines for some popular extensions\n'
+                '# inotify =\n'
+                '# win32mbcs =\n'
+                '# win32text =\n',
+                }
+
+            if opts.get('global'):
+                samplehgrc = samplehgrcs['global']
+            elif opts.get('local'):
+                samplehgrc = samplehgrcs['local']
+            else:
+                samplehgrc = samplehgrcs['user']
+
+            f = paths[0]
+            fp = open(f, "w")
+            fp.write(samplehgrc)
             fp.close()
 
         editor = ui.geteditor()


More information about the Mercurial-devel mailing list