changeset 29634:8421cbebc783 stable

keyword: avoid traceback when kwdemo is run outside a repo f0564402d059 causes a fatal AttributeError if kwdemo is run outside a repo because in the temporary repo creation repo is None and therefore cannot have a baseui attribute. In this case fall back to using ui. Add test case.
author Christian Ebert <blacktrash@gmx.net>
date Wed, 27 Jul 2016 13:57:51 +0100
parents bc5148d0a446
children dee24c87dbf0
files hgext/keyword.py tests/test-keyword.t
diffstat 2 files changed, 17 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/keyword.py	Wed Jul 27 08:38:54 2016 +0000
+++ b/hgext/keyword.py	Wed Jul 27 13:57:51 2016 +0100
@@ -412,7 +412,11 @@
     fn = 'demo.txt'
     tmpdir = tempfile.mkdtemp('', 'kwdemo.')
     ui.note(_('creating temporary repository at %s\n') % tmpdir)
-    repo = localrepo.localrepository(repo.baseui, tmpdir, True)
+    if repo is None:
+        baseui = ui
+    else:
+        baseui = repo.baseui
+    repo = localrepo.localrepository(baseui, tmpdir, True)
     ui.setconfig('keyword', fn, '', 'keyword')
     svn = ui.configbool('keywordset', 'svn')
     # explicitly set keywordset for demo output
--- a/tests/test-keyword.t	Wed Jul 27 08:38:54 2016 +0000
+++ b/tests/test-keyword.t	Wed Jul 27 13:57:51 2016 +0100
@@ -1,3 +1,15 @@
+Run kwdemo outside a repo
+  $ hg -q --config extensions.keyword= --config keywordmaps.Foo="{author|user}" kwdemo
+  [extensions]
+  keyword =
+  [keyword]
+  demo.txt = 
+  [keywordset]
+  svn = False
+  [keywordmaps]
+  Foo = {author|user}
+  $Foo: test $
+
   $ cat <<EOF >> $HGRCPATH
   > [extensions]
   > keyword =