Browse Source

More config fixes.

Jelmer Vernooij 13 years ago
parent
commit
78f95ecdb1
2 changed files with 13 additions and 2 deletions
  1. 8 2
      dulwich/config.py
  2. 5 0
      dulwich/tests/test_config.py

+ 8 - 2
dulwich/config.py

@@ -127,9 +127,15 @@ class ConfigFile(ConfigDict):
             line = line.lstrip()
             line = line.lstrip()
             if setting is None:
             if setting is None:
                 if line[0] == "[" and line.rstrip()[-1] == "]":
                 if line[0] == "[" and line.rstrip()[-1] == "]":
-                    section = (line.strip()[1:-1], None)
+                    key = line.strip()
+                    pts = key[1:-1].split(" ", 1)
+                    if len(pts) == 2:
+                        if pts[1][0] != "\"" or pts[1][-1] != "\"":
+                            raise ValueError(pts[1])
+                        section = (pts[0], pts[1][1:-1])
+                    else:
+                        section = (pts[0], None)
                     ret._values[section[0]] = {section[1]: {}}
                     ret._values[section[0]] = {section[1]: {}}
-                    # FIXME: Parse section
                 elif "=" in line:
                 elif "=" in line:
                     setting, value = line.split("=", 1)
                     setting, value = line.split("=", 1)
                     if section is None:
                     if section is None:

+ 5 - 0
dulwich/tests/test_config.py

@@ -47,6 +47,11 @@ class ConfigFileTests(TestCase):
     def test_from_file_section(self):
     def test_from_file_section(self):
         cf = self.from_file("[core]\nfoo = bar\n")
         cf = self.from_file("[core]\nfoo = bar\n")
         self.assertEquals("bar", cf.get("core.foo"))
         self.assertEquals("bar", cf.get("core.foo"))
+        self.assertEquals("bar", cf.get("core.foo.foo"))
+
+    def test_from_file_subsection(self):
+        cf = self.from_file("[branch \"foo\"]\nfoo = bar\n")
+        self.assertEquals("bar", cf.get("branch.foo.foo"))
 
 
     def test_write_to_file_empty(self):
     def test_write_to_file_empty(self):
         c = ConfigFile()
         c = ConfigFile()