Make parsing config file sections symmetric
authorGuido Günther <agx@sigxcpu.org>
Sun, 5 Jan 2014 14:41:44 +0000 (15:41 +0100)
committerGuido Günther <agx@sigxcpu.org>
Sun, 5 Jan 2014 14:41:44 +0000 (15:41 +0100)
Always read the legacy command's config file section prior to the
subcommand's config file section.

Until now 'gbp <subcommand>' would read '[subcommand]' as well as
'[gbp-<subcommand>]' sections while 'gbp-<subcommand>' would only read
'[gbp-<subcommand>]' sections.

Closes: #733759

gbp/config.py

index 4952de4..f17d57f 100644 (file)
@@ -318,18 +318,24 @@ class GbpOptionParser(OptionParser):
         parser.read(self.config_files)
         self.config.update(dict(parser.defaults()))
 
-        if not (self.command.startswith('gbp-') or
-                self.command.startswith('git-')):
-            # Invoked as gbp <command> syntax, so parse the old sections
-            # of {gbp.git}-<command> for backward compatibility:
+        # Make sure we read any legacy sections prior to the real subcommands
+        # section i.e. read [gbp-pull] prior to [pull]
+        if (self.command.startswith('gbp-') or
+            self.command.startswith('git-')):
+            oldcmd = self.command
+            if parser.has_section(oldcmd):
+                self.config.update(dict(parser.items(oldcmd, raw=True)))
+            cmd = self.command[4:]
+        else:
             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)))
+            cmd = self.command
 
         # Update with command specific settings
-        if parser.has_section(self.command):
-            self.config.update(dict(parser.items(self.command, raw=True)))
+        if parser.has_section(cmd):
+            self.config.update(dict(parser.items(cmd, raw=True)))
 
         for section in self.sections:
             if parser.has_section(section):