Patchwork [STABLE] templater: selecting a style with no templates does not crash (issue4140)

login
register
mail settings
Submitter Simon Heimberg
Date Jan. 23, 2014, 12:38 a.m.
Message ID <7da0079b4722f76d29bf.1390437480@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/3401/
State Accepted
Commit 268a5ab5c27bee4312c5f060cefab4de6cbdadba
Headers show

Comments

Simon Heimberg - Jan. 23, 2014, 12:38 a.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1390436990 -3600
# Branch stable
# Node ID 7da0079b4722f76d29bfd3295a5fc926d57a758d
# Parent  47511b006e57dc5c50a361d40c35e1a03241a907
templater: selecting a style with no templates does not crash (issue4140)

Running `hg log --style compact` (or any other style) raised a traceback when
no template directory was there. Now there is a message:

Abort: style 'compact' not found
(available styles: no templates found, try `hg debuginstall` for more info)


There is no test because this would require to rename the template directory.
But this would influence other tests running in parallel. And when the test
would be aborted the wrong named directory would remain, especially a problem
when running with -l.
Matt Mackall - Jan. 23, 2014, 8:32 p.m.
On Thu, 2014-01-23 at 01:38 +0100, Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe@besonet.ch>
> # Date 1390436990 -3600
> # Branch stable
> # Node ID 7da0079b4722f76d29bfd3295a5fc926d57a758d
> # Parent  47511b006e57dc5c50a361d40c35e1a03241a907
> templater: selecting a style with no templates does not crash (issue4140)

Thanks, queued for stable.

Patch

diff -r 47511b006e57 -r 7da0079b4722 mercurial/templater.py
--- a/mercurial/templater.py	Don Jan 23 01:21:08 2014 +0100
+++ b/mercurial/templater.py	Don Jan 23 01:29:50 2014 +0100
@@ -447,8 +447,10 @@ 
 engines = {'default': engine}
 
 def stylelist():
-    path = templatepath()[0]
-    dirlist =  os.listdir(path)
+    paths = templatepath()
+    if not paths:
+        return _('no templates found, try `hg debuginstall` for more info')
+    dirlist =  os.listdir(paths[0])
     stylelist = []
     for file in dirlist:
         split = file.split(".")