[PATCH STABLE V2] keyword: avoid traceback when kwdemo is run outside a repo

Christian Ebert blacktrash at gmx.net
Wed Jul 27 17:37:18 EDT 2016


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1469624271 -3600
#      Wed Jul 27 13:57:51 2016 +0100
# Branch stable
# Node ID 591ba25e00ddcb93e20a7bdb3fc7091183522709
# Parent  6217180f9ab8c61320ea3826591960415779282e
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.

diff --git a/hgext/keyword.py b/hgext/keyword.py
--- a/hgext/keyword.py
+++ b/hgext/keyword.py
@@ -412,7 +412,11 @@ def demo(ui, repo, *args, **opts):
     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 == 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
diff --git a/tests/test-keyword.t b/tests/test-keyword.t
--- a/tests/test-keyword.t
+++ b/tests/test-keyword.t
@@ -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 =


More information about the Mercurial-devel mailing list