diff --git a/git_config.py b/git_config.py index e658b059..e1e20463 100644 --- a/git_config.py +++ b/git_config.py @@ -265,9 +265,11 @@ class GitConfig(object): This internal method populates the GitConfig cache. """ - d = self._do('--null', '--list').rstrip('\0') c = {} - for line in d.split('\0'): + d = self._do('--null', '--list') + if d is None: + return c + for line in d.rstrip('\0').split('\0'): if '\n' in line: key, val = line.split('\n', 1) else: diff --git a/tests/test_git_config.py b/tests/test_git_config.py index d67a8bab..5b1770e7 100644 --- a/tests/test_git_config.py +++ b/tests/test_git_config.py @@ -39,5 +39,14 @@ class GitConfigUnitTest(unittest.TestCase): val = self.config.GetString('section.nonempty') self.assertEqual(val, 'true') + def test_GetString_from_missing_file(self): + """ + Test missing config file + """ + config_fixture = fixture('not.present.gitconfig') + config = git_config.GitConfig(config_fixture) + val = config.GetString('empty') + self.assertEqual(val, None) + if __name__ == '__main__': unittest.main()