summaryrefslogtreecommitdiff
path: root/git/config.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-09-06 15:11:54 +0200
committerSebastian Thiel <byronimo@gmail.com>2015-09-06 15:11:54 +0200
commit074842accb51b2a0c2c1193018d9f374ac5e948f (patch)
treefcb08fd49fe7e239e5defbb1de277054fe7b94f2 /git/config.py
parent7f8d9ca08352a28cba3b01e4340a24edc33e13e8 (diff)
downloadgitpython-074842accb51b2a0c2c1193018d9f374ac5e948f.tar.gz
fix(config): ignore empty values in config file
Similar to git, we now ignore options which have no value. Previously it would not handle it consistently, and throw a parsing error the first time the cache was built. Afterwards, it was fully usable though. Now we specifically check for the case of no-value options instead. Closes #349
Diffstat (limited to 'git/config.py')
-rw-r--r--git/config.py20
1 files changed, 14 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()