Bug 4151 - hg debuginstall does not show missing template directory as a problem
Summary: hg debuginstall does not show missing template directory as a problem
Status: RESOLVED FIXED
Alias: None
Product: Mercurial
Classification: Unclassified
Component: Mercurial (show other bugs)
Version: 2.9-rc
Hardware: PC All
: normal bug
Assignee: Bugzilla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-23 11:41 UTC by Simon Heimberg
Modified: 2014-07-19 14:17 UTC (History)
1 user (show)

See Also:
Python Version: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Heimberg 2014-01-23 11:41 UTC
When there is no template directory hg debuginstall does not report this as a problem. It only reports empty brackets 
  $ hg debuginstall
  *...some lines*
  checking templates ()...
  *...some lines*
  no problems detected

to reproduce, rename the mercurial/templates directory (to templates_), 
and run hg debuginstall


Cause
=====

Looks like this line in templater.py [1] does not raise an error:
    templater.templater(templater.templatepath("map-cmdline.default"))

This is because templatepath returns [] when not found, and templater([]) returns a valid empty templater instance.

Testing with run-tests.py
=========================

Not trivial, because the test should not rename the templates directory.
(Other tests running parallel could fail. And when the test can not finish 
properly, the wrong named directory remains.)
A test extension could monkey patch templater.templatepath. But not sure if this is a good approach, because this requires to synchronize changes to templater.templatepath to the patched version.
When a test is written, please also run `hg log --style compact` to test issue 4140 (which also requires a missing template directory).
Comment 1 Simon Heimberg 2014-01-27 02:56 UTC
(In reply to comment #0)
missing link to unfailing line in templater.py:
[1] 
http://hg.intevation.org/mercurial/crew/file/2cfb720592fe/mercurial/commands.py#l2097
Comment 2 HG Bot 2014-02-07 18:45 UTC
Fixed by http://selenic.com/repo/hg/rev/9a86b5b8e0d8
Simon Heimberg <simohe@besonet.ch>
commands: hg debuginstall checks missing templates (issue4151)

Missing templates where not reported as a problem, only an empty bracket
were shown as indication of no found template directory:
  $ hg debuginstall
  *...some lines*
  checking templates ()...
  *...some lines*
  no problems detected

Now the problem is reported and extended with some information. The style
of the messages is adapted to the other messages of debuginstall.

When no templates directories exist, it writes:
  $ hg debuginstall
  *...some lines*
  checking templates ()...
   no template directories found
   (templates seem to have been installed incorrectly)
  *...some lines*
  1 problems detected, please check your install!

When the template map is not found, it writes:
  $ hg debuginstall
  *...some lines*
  checking templates (/path/to/mercurial/templates)...
   template 'default' not found
   (templates seem to have been installed incorrectly)
  *...some lines*
  1 problems detected, please check your install!

When the template map is buggy the message is the same as before. The error
message is shown before the line "(templates seem ...)".


No test is added because testing this failure is complicated. It would
require to modify the templates directory of the mercurial installation,
or to monkey patch a function (os.listdir or any from mercurial.templater)
by a test extension.

(please test the fix)