summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--git/config.py20
-rw-r--r--git/test/fixtures/git_config_with_empty_value4
-rw-r--r--git/test/test_config.py7
3 files changed, 25 insertions, 6 deletions
diff --git a/git/config.py b/git/config.py
index b7ddf0d2..ea5e17be 100644
--- a/git/config.py
+++ b/git/config.py
@@ -156,15 +156,21 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
#} END configuration
+ optvalueonly_source = r'\s*(?P<option>[^:=\s][^:=]*)'
+
+ OPTVALUEONLY = re.compile(optvalueonly_source)
+
OPTCRE = re.compile(
- r'\s*(?P<option>[^:=\s][^:=]*)' # very permissive, incuding leading whitespace
- r'\s*(?P<vi>[:=])\s*' # any number of space/tab,
+ optvalueonly_source # very permissive, incuding leading whitespace
+ + r'\s*(?P<vi>[:=])\s*' # any number of space/tab,
# followed by separator
# (either : or =), followed
# by any # space/tab
- r'(?P<value>.*)$' # everything up to eol
+ + r'(?P<value>.*)$' # everything up to eol
)
+ del optvalueonly_source
+
# list of RawConfigParser methods able to change the instance
_mutating_methods_ = ("add_section", "remove_section", "remove_option", "set")
@@ -322,9 +328,11 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
# end handle multi-line
cursect[optname] = optval
else:
- if not e:
- e = cp.ParsingError(fpname)
- e.append(lineno, repr(line))
+ # check if it's an option with no value - it's just ignored by git
+ if not self.OPTVALUEONLY.match(line):
+ if not e:
+ e = cp.ParsingError(fpname)
+ e.append(lineno, repr(line))
continue
else:
line = line.rstrip()
diff --git a/git/test/fixtures/git_config_with_empty_value b/git/test/fixtures/git_config_with_empty_value
new file mode 100644
index 00000000..0427caea
--- /dev/null
+++ b/git/test/fixtures/git_config_with_empty_value
@@ -0,0 +1,4 @@
+[color]
+ ui
+[core]
+ filemode = true \ No newline at end of file
diff --git a/git/test/test_config.py b/git/test/test_config.py
index 7758a094..22f342aa 100644
--- a/git/test/test_config.py
+++ b/git/test/test_config.py
@@ -210,3 +210,10 @@ class TestBase(TestCase):
self.assertEqual(w_config.get('alias', 'rbi'), '"!g() { git rebase -i origin/${1:-master} ; } ; g"')
w_config.release()
self.assertEqual(file_obj.getvalue(), self._to_memcache(fixture_path('.gitconfig')).getvalue())
+
+ def test_empty_config_value(self):
+ cr = GitConfigParser(fixture_path('git_config_with_empty_value'), read_only=True)
+
+ assert cr.get_value('core', 'filemode'), "Should read keys with values"
+
+ self.failUnlessRaises(cp.NoOptionError, cr.get_value, 'color', 'ui')