summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-12-09 21:38:12 +0100
committerSebastian Thiel <byronimo@gmail.com>2009-12-09 21:38:12 +0100
commita97d21936200f1221d8ddd89202042faed1b9bcb (patch)
treed545db205d0bd731fc16d19663f7028dabe0f57d
parent35057c56ce118e4cbd0584bd4690e765317b4c38 (diff)
downloadgitpython-a97d21936200f1221d8ddd89202042faed1b9bcb.tar.gz
config: fixed incorrect handling of default value in get_value
remote.config: SectionConstraint now knows about set_value and get_value which are new to the GitConfigParser
-rw-r--r--lib/git/config.py4
-rw-r--r--lib/git/remote.py6
-rw-r--r--test/git/test_config.py4
-rw-r--r--test/git/test_remote.py1
4 files changed, 11 insertions, 4 deletions
diff --git a/lib/git/config.py b/lib/git/config.py
index e8bdfc75..7a09a63c 100644
--- a/lib/git/config.py
+++ b/lib/git/config.py
@@ -360,7 +360,9 @@ class GitConfigParser(cp.RawConfigParser, LockFile):
try:
valuestr = self.get(section, option)
except Exception:
- return default
+ if default is not None:
+ return default
+ raise
types = ( long, float )
for numtype in types:
diff --git a/lib/git/remote.py b/lib/git/remote.py
index e1d0d743..1e2e42fa 100644
--- a/lib/git/remote.py
+++ b/lib/git/remote.py
@@ -21,7 +21,7 @@ class _SectionConstraint(object):
It supports all ConfigParser methods that operate on an option
"""
__slots__ = ("_config", "_section_name")
- _valid_attrs_ = ("get", "set", "getint", "getfloat", "getboolean", "has_option")
+ _valid_attrs_ = ("get_value", "set_value", "get", "set", "getint", "getfloat", "getboolean", "has_option")
def __init__(self, config, section):
self._config = config
@@ -32,10 +32,10 @@ class _SectionConstraint(object):
return lambda *args: self._call_config(attr, *args)
return super(_SectionConstraint,self).__getattribute__(attr)
- def _call_config(self, method, *args):
+ def _call_config(self, method, *args, **kwargs):
"""Call the configuration at the given method which must take a section name
as first argument"""
- return getattr(self._config, method)(self._section_name, *args)
+ return getattr(self._config, method)(self._section_name, *args, **kwargs)
class PushProgress(object):
diff --git a/test/git/test_config.py b/test/git/test_config.py
index 6103ab8d..407eb9bd 100644
--- a/test/git/test_config.py
+++ b/test/git/test_config.py
@@ -8,6 +8,7 @@ from test.testlib import *
from git import *
import StringIO
from copy import copy
+from ConfigParser import NoSectionError
class TestBase(TestCase):
@@ -97,4 +98,7 @@ class TestBase(TestCase):
default = "my default value"
assert r_config.get_value("doesnt", "exist", default) == default
+ # it raises if there is no default though
+ self.failUnlessRaises(NoSectionError, r_config.get_value, "doesnt", "exist")
+
diff --git a/test/git/test_remote.py b/test/git/test_remote.py
index edbf758c..a9ca8331 100644
--- a/test/git/test_remote.py
+++ b/test/git/test_remote.py
@@ -358,6 +358,7 @@ class TestRemote(TestBase):
val = getattr(remote, opt)
reader = remote.config_reader
assert reader.get(opt) == val
+ assert reader.get_value(opt, None) == val
# unable to write with a reader
self.failUnlessRaises(IOError, reader.set, opt, "test")