Skip to content

Commit a97d219

Browse files
committed
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
1 parent 35057c5 commit a97d219

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

lib/git/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ def get_value(self, section, option, default = None):
360360
try:
361361
valuestr = self.get(section, option)
362362
except Exception:
363-
return default
363+
if default is not None:
364+
return default
365+
raise
364366

365367
types = ( long, float )
366368
for numtype in types:

lib/git/remote.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class _SectionConstraint(object):
2121
It supports all ConfigParser methods that operate on an option
2222
"""
2323
__slots__ = ("_config", "_section_name")
24-
_valid_attrs_ = ("get", "set", "getint", "getfloat", "getboolean", "has_option")
24+
_valid_attrs_ = ("get_value", "set_value", "get", "set", "getint", "getfloat", "getboolean", "has_option")
2525

2626
def __init__(self, config, section):
2727
self._config = config
@@ -32,10 +32,10 @@ def __getattr__(self, attr):
3232
return lambda *args: self._call_config(attr, *args)
3333
return super(_SectionConstraint,self).__getattribute__(attr)
3434

35-
def _call_config(self, method, *args):
35+
def _call_config(self, method, *args, **kwargs):
3636
"""Call the configuration at the given method which must take a section name
3737
as first argument"""
38-
return getattr(self._config, method)(self._section_name, *args)
38+
return getattr(self._config, method)(self._section_name, *args, **kwargs)
3939

4040

4141
class PushProgress(object):

test/git/test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from git import *
99
import StringIO
1010
from copy import copy
11+
from ConfigParser import NoSectionError
1112

1213
class TestBase(TestCase):
1314

@@ -97,4 +98,7 @@ def test_base(self):
9798
default = "my default value"
9899
assert r_config.get_value("doesnt", "exist", default) == default
99100

101+
# it raises if there is no default though
102+
self.failUnlessRaises(NoSectionError, r_config.get_value, "doesnt", "exist")
103+
100104

test/git/test_remote.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ def test_base(self, rw_repo, remote_repo):
358358
val = getattr(remote, opt)
359359
reader = remote.config_reader
360360
assert reader.get(opt) == val
361+
assert reader.get_value(opt, None) == val
361362

362363
# unable to write with a reader
363364
self.failUnlessRaises(IOError, reader.set, opt, "test")

0 commit comments

Comments
 (0)