@@ 124,6 124,13 @@ def prompt(ui, repo, fs='', **opts):
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 @@ def prompt(ui, repo, fs='', **opts):
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 @@ def prompt(ui, repo, fs='', **opts):
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)
@@ 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'