Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix error parsing a non-existant configuration file

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>
  • Loading branch information...
commit c24c720b6135a8f7975bf9af265124eee2d464cb 1 parent 2d1a396
@spearce spearce authored
Showing with 13 additions and 2 deletions.
  1. +4 −2 git_config.py
  2. +9 −0 tests/test_git_config.py
View
6 git_config.py
@@ -265,9 +265,11 @@ def _ReadGit(self):
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:
View
9 tests/test_git_config.py
@@ -39,5 +39,14 @@ def test_GetString_with_true_value(self):
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()
Please sign in to comment.
Something went wrong with that request. Please try again.