diff options
author | Shawn O. Pearce <sop@google.com> | 2009-07-02 16:12:57 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-07-02 16:12:57 -0700 |
commit | c24c720b6135a8f7975bf9af265124eee2d464cb (patch) | |
tree | c1460ab9ad60850aed68b25ba6d98a931adc352e | |
parent | 2d1a3968971366fab7000664959a2d5a39b48996 (diff) | |
download | git-repo-c24c720b6135a8f7975bf9af265124eee2d464cb.tar.gz |
Fix error parsing a non-existant configuration filev1.6.8.7
If a file (e.g. ~/.gitconfig) does not exist, we get None
here rather than a string. NoneType lacks rstrip() so we
cannot strip it.
Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r-- | git_config.py | 6 | ||||
-rw-r--r-- | tests/test_git_config.py | 9 |
2 files changed, 13 insertions, 2 deletions
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): | |||
265 | This internal method populates the GitConfig cache. | 265 | This internal method populates the GitConfig cache. |
266 | 266 | ||
267 | """ | 267 | """ |
268 | d = self._do('--null', '--list').rstrip('\0') | ||
269 | c = {} | 268 | c = {} |
270 | for line in d.split('\0'): | 269 | d = self._do('--null', '--list') |
270 | if d is None: | ||
271 | return c | ||
272 | for line in d.rstrip('\0').split('\0'): | ||
271 | if '\n' in line: | 273 | if '\n' in line: |
272 | key, val = line.split('\n', 1) | 274 | key, val = line.split('\n', 1) |
273 | else: | 275 | 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): | |||
39 | val = self.config.GetString('section.nonempty') | 39 | val = self.config.GetString('section.nonempty') |
40 | self.assertEqual(val, 'true') | 40 | self.assertEqual(val, 'true') |
41 | 41 | ||
42 | def test_GetString_from_missing_file(self): | ||
43 | """ | ||
44 | Test missing config file | ||
45 | """ | ||
46 | config_fixture = fixture('not.present.gitconfig') | ||
47 | config = git_config.GitConfig(config_fixture) | ||
48 | val = config.GetString('empty') | ||
49 | self.assertEqual(val, None) | ||
50 | |||
42 | if __name__ == '__main__': | 51 | if __name__ == '__main__': |
43 | unittest.main() | 52 | unittest.main() |