003e92ae20da

Command line overwrites format string from HGRC

Also extends help to mention hgrc setting.
[view raw] [browse files]
author Oben Sonne <obensonne@googlemail.com>
date Wed, 05 Oct 2016 10:45:22 +0200
parents 2e292ca8d768
children 064a8c1d11be
branches/tags (none)
files prompt.py tests/test_hgrc.py

Changes

--- a/prompt.py	Thu Feb 27 14:39:40 2014 +0100
+++ b/prompt.py	Wed Oct 05 10:45:22 2016 +0200
@@ -98,6 +98,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):
@@ -426,9 +433,8 @@
     if opts.get("cache_outgoing"):
         _cache_remote(repo, 'outgoing')
 
-    hgrc_fs = repo.ui.config("prompt", "template")
-    if hgrc_fs is not None:
-        fs = hgrc_fs
+    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)
--- a/tests/test_hgrc.py	Thu Feb 27 14:39:40 2014 +0100
+++ b/tests/test_hgrc.py	Wed Oct 05 10:45:22 2016 +0200
@@ -8,16 +8,16 @@
 def test_hgrc():
 
     with open(os.path.join(sandbox_path, '.hg', 'hgrc'), 'w') as fp:
-        fp.write('[prompt]\ntemplate =\n')
+        fp.write('[prompt]\ntemplate = foo\n')
 
-    output = prompt(fs='{node}')
-    assert output == ''
+    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='{node}')
-    assert output == ' at node 0000000000000000000000000000000000000000'
-
     output = prompt(fs='')
     assert output == ' at node 0000000000000000000000000000000000000000'