Skip to content

Commit

Permalink
new: reference config file is not anymore required. (fixes #54)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaab committed Feb 22, 2017
1 parent c607a32 commit 70529cf
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
18 changes: 11 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,17 @@ the `changelog of the PyPI page`_.
Usage
=====

The `reference configuration file`_ is delivered within ``gitchangelog`` package
and provides defaults for settings.

You *may* place a ``gitchangelog.rc`` file somewhere to override the defaults.
The recommended location is the root of the current git repository with
the name ``.gitchangelog.rc``. However you could put it elsewhere,
and here are the locations checked (first match will prevail):
The `reference configuration file`_ is delivered within
``gitchangelog`` package and is used to provides defaults to
settings. If you didn't install the package and used the standalone
file, then chances are that ``gitchangelog`` can't access these
defaults values. This is not a problem as long as you provided all the
required values in your config file.

The recommended location for ``gitchangelog`` config file is the root
of the current git repository with the name ``.gitchangelog.rc``.
However you could put it elsewhere, and here are the locations checked
(first match will prevail):

- in the path given thanks to the environment variable
``GITCHANGELOG_CONFIG_FILENAME``
Expand Down
17 changes: 14 additions & 3 deletions src/gitchangelog/gitchangelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,18 @@ def get_log_encoding(repository, config):
return log_encoding or DEFAULT_GIT_LOG_ENCODING


##
## Config Manager
##

class Config(dict):

def __getitem__(self, label):
if label not in self.keys():
die("Missing value in config file for key '%s'." % label)
return super(Config, self).__getitem__(label)


##
## Main
##
Expand Down Expand Up @@ -1545,9 +1557,6 @@ def main():
else:
break

if not os.path.exists(reference_config):
die("Config reference file %r not found." % reference_config)

## config file may lookup for templates relative to the toplevel
## of git repository
os.chdir(repository.toplevel)
Expand All @@ -1557,6 +1566,8 @@ def main():
default_filename=reference_config,
fail_if_not_present=False)

config = Config(config)

log_encoding = get_log_encoding(repository, config)
revlist = get_revision(repository, config, opts)
manage_obsolete_options(config)
Expand Down
42 changes: 42 additions & 0 deletions test/test_issue54.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- encoding: utf-8 -*-
"""Reference file is not required to be found
Tests issue #54
(https://github.com/vaab/gitchangelog/issues/54)
"""

from __future__ import unicode_literals

from common import BaseGitReposTest, cmd, file_put_contents


class TestConfigComplains(BaseGitReposTest):

def test_missing_option(self):
super(TestConfigComplains, self).setUp()

file_put_contents(
".gitchangelog.rc",
"del section_regexps"
)

out, err, errlvl = cmd('$tprog --debug')
self.assertContains(
err.lower(), "missing value",
msg="There should be an error message containing 'missing value'. "
"Current stderr:\n%s" % err)
self.assertContains(
err.lower(), "config file",
msg="There should be an error message containing 'config file'. "
"Current stderr:\n%s" % err)
self.assertContains(
err.lower(), "section_regexps",
msg="There should be an error message containing 'section_regexps'. "
"Current stderr:\n%s" % err)
self.assertEqual(
errlvl, 1,
msg="Should faild.")
self.assertEqual(
out, "",
msg="No output is expected.")

0 comments on commit 70529cf

Please sign in to comment.