5334581e231a

Merge.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 05 Oct 2016 20:52:29 +0000
parents 4d7402d28abf (current diff) 064a8c1d11be (diff)
children 4dddc56c4c4b
branches/tags (none)
files prompt.py

Changes

--- a/prompt.py	Tue Oct 04 10:49:19 2016 +0000
+++ b/prompt.py	Wed Oct 05 20:52:29 2016 +0000
@@ -124,6 +124,13 @@
         currently at my-bookmark
 
     See 'hg help prompt-keywords' for a list of available keywords.
+
+    The format string may also be defined in an hgrc file::
+
+        [prompt]
+        template = {currently at {bookmark}}
+
+    This is used when no format string is passed on the command line.
     '''
 
     def _basename(m):
@@ -392,7 +399,6 @@
 
         return _with_groups(m.groups(), '^') if current_rev.children() else ''
 
-
     if opts.get("angle_brackets"):
         tag_start = r'\<([^><]*?\<)?'
         tag_end = r'(\>[^><]*?)?>'
@@ -463,6 +469,9 @@
     if opts.get("cache_outgoing"):
         _cache_remote(repo, 'outgoing')
 
+    if not fs:
+        fs = repo.ui.config("prompt", "template", "")
+
     for tag, repl in patterns.items():
         fs = re.sub(tag_start + tag + tag_end, repl, fs)
     ui.status(fs)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_hgrc.py	Wed Oct 05 20:52:29 2016 +0000
@@ -0,0 +1,23 @@
+'''Test evaluation of prompt template in HGRC.'''
+
+from nose import *
+from util import *
+
+
+@with_setup(setup_sandbox, teardown_sandbox)
+def test_hgrc():
+
+    with open(os.path.join(sandbox_path, '.hg', 'hgrc'), 'w') as fp:
+        fp.write('[prompt]\ntemplate = foo\n')
+
+    output = prompt(fs='')
+    assert output == 'foo'
+
+    output = prompt(fs='bar')
+    assert output == 'bar'  # command line overwrites hgrc
+
+    with open(os.path.join(sandbox_path, '.hg', 'hgrc'), 'w') as fp:
+        fp.write('[prompt]\ntemplate = { at node {node}}\n')
+
+    output = prompt(fs='')
+    assert output == ' at node 0000000000000000000000000000000000000000'