Skip to content

Commit

Permalink
Add parse_submodules function.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Jun 8, 2016
1 parent 0e53006 commit e557e76
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Expand Up @@ -5,6 +5,10 @@
* Fix ShaFile.id after modification of a copied ShaFile.
(Félix Mattrat, Jelmer Vernooij)

IMPROVEMENTS

* Add `dulwich.config.parse_submodules` function.

0.13.0 2016-04-24

IMPROVEMENTS
Expand Down
15 changes: 15 additions & 0 deletions dulwich/config.py
Expand Up @@ -417,3 +417,18 @@ def set(self, section, name, value):
if self.writable is None:
raise NotImplementedError(self.set)
return self.writable.set(section, name, value)


def parse_submodules(config):
"""Parse a gitmodules GitConfig file, returning submodules.
:param config: A `ConfigFile`
:return: list of tuples (submodule path, url, name),
where name is quoted part of the section's name.
"""
for section in config.keys():
section_kind, section_name = section
if section_kind == 'submodule':
sm_path = config.get(section, 'path')
sm_url = config.get(section, 'url')
yield (sm_path, sm_url, section_name)
14 changes: 14 additions & 0 deletions dulwich/tests/test_config.py
Expand Up @@ -29,6 +29,7 @@
_escape_value,
_parse_string,
_unescape_value,
parse_submodules,
)
from dulwich.tests import (
TestCase,
Expand Down Expand Up @@ -292,3 +293,16 @@ def test_valid(self):
self.assertTrue(_check_section_name(b"foo"))
self.assertTrue(_check_section_name(b"foo-bar"))
self.assertTrue(_check_section_name(b"bar.bar"))


class SubmodulesTests(TestCase):

def testSubmodules(self):
cf = ConfigFile.from_file(BytesIO(b"""\
[submodule "core/lib"]
path = core/lib
url = https://github.com/phhusson/QuasselC.git
"""))
got = list(parse_submodules(cf))
self.assertEqual([
('core/lib', 'https://github.com/phhusson/QuasselC.git', 'core/lib')], got)

0 comments on commit e557e76

Please sign in to comment.