summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/git/config.py12
-rw-r--r--test/git/test_config.py5
2 files changed, 15 insertions, 2 deletions
diff --git a/lib/git/config.py b/lib/git/config.py
index 2f567559..1739e786 100644
--- a/lib/git/config.py
+++ b/lib/git/config.py
@@ -347,13 +347,21 @@ class GitConfigParser(cp.RawConfigParser, LockFile):
"""
return self._read_only
- def get_value(self, section, option):
+ def get_value(self, section, option, default = None):
"""
+ ``default``
+ If not None, the given default value will be returned in case
+ the option did not exist
Returns
a properly typed value, either int, float or string
Raises TypeError in case the value could not be understood
+ Otherwise the exceptions known to the ConfigParser will be raised.
"""
- valuestr = self.get(section, option)
+ try:
+ valuestr = self.get(section, option)
+ except Exception:
+ return default
+
types = ( long, float )
for numtype in types:
try:
diff --git a/test/git/test_config.py b/test/git/test_config.py
index 4b6c4f11..e3d723a0 100644
--- a/test/git/test_config.py
+++ b/test/git/test_config.py
@@ -87,3 +87,8 @@ class TestBase(TestCase):
assert num_sections and num_options
assert r_config._is_initialized == True
+ # get value which doesnt exist, with default
+ default = "my default value"
+ assert r_config.get_value("doesnt", "exist", default) == default
+
+