diff options
author | Guido Günther <agx@sigxcpu.org> | 2013-06-19 00:25:53 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2013-06-19 14:55:44 +0200 |
commit | fe9f925c3cd4703ecf9409544d8692d677e32ff6 (patch) | |
tree | 4faaba554967959e64ca2489715a775975cfbec5 | |
parent | caff99cb63b4837eb91d5ee312c2c36663c08c88 (diff) |
GbpOptionParser: Make sure we parse the old config sections
For backward compatibility between {gbp,git}-<subcommand> and "gbp
<subcommand>" make sure we parse the former sections if using the later.
-rw-r--r-- | gbp/config.py | 9 | ||||
-rw-r--r-- | tests/test_Config.py | 21 |
2 files changed, 30 insertions, 0 deletions
diff --git a/gbp/config.py b/gbp/config.py index 16faab1..f61ebc5 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -311,6 +311,15 @@ class GbpOptionParser(OptionParser): parser.read(self.config_files) self.config = dict(parser.defaults()) + if not (self.command.startswith('gbp-') or + self.command.startswith('git-')): + # Invoked as gbp <subcommand> syntax, so parse the old sections + # of {gbp.git}-<subcommand> for backward compatibility: + for prefix in ['gbp', 'git']: + oldcmd = '%s-%s' % (prefix, self.command) + if parser.has_section(oldcmd): + self.config.update(dict(parser.items(oldcmd, raw=True))) + if parser.has_section(self.command): self.config.update(dict(parser.items(self.command, raw=True))) diff --git a/tests/test_Config.py b/tests/test_Config.py index 3f19dc5..9fe7dd4 100644 --- a/tests/test_Config.py +++ b/tests/test_Config.py @@ -59,3 +59,24 @@ def test_tristate(): >>> options.color auto """ + +def test_parser_fallback(): + """ + Make sure we also parse git-<subcommands> sections if + gbp <subcommand> was used. + + >>> import os + >>> from gbp.config import GbpOptionParser + >>> parser = GbpOptionParser('foo') + >>> tmpdir = str(context.new_tmpdir('foo')) + >>> confname = os.path.join(tmpdir, 'gbp.conf') + >>> parser.config_files = [confname] + >>> f = file(confname, 'w') + >>> f.write('[foo]\\nthere = is\\n[git-foo]\\nno = truth\\n') + >>> f.close() + >>> parser._parse_config_files() + >>> parser.config['there'] + 'is' + >>> parser.config['no'] + 'truth' + """ |