Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit074842a

Browse files
committed
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 parsingerror 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
1 parent7f8d9ca commit074842a

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

‎git/config.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,21 @@ class GitConfigParser(with_metaclass(MetaParserBuilder, cp.RawConfigParser, obje
156156

157157
#} END configuration
158158

159+
optvalueonly_source=r'\s*(?P<option>[^:=\s][^:=]*)'
160+
161+
OPTVALUEONLY=re.compile(optvalueonly_source)
162+
159163
OPTCRE=re.compile(
160-
r'\s*(?P<option>[^:=\s][^:=]*)'# very permissive, incuding leading whitespace
161-
r'\s*(?P<vi>[:=])\s*'# any number of space/tab,
164+
optvalueonly_source# very permissive, incuding leading whitespace
165+
+r'\s*(?P<vi>[:=])\s*'# any number of space/tab,
162166
# followed by separator
163167
# (either : or =), followed
164168
# by any # space/tab
165-
r'(?P<value>.*)$'# everything up to eol
169+
+r'(?P<value>.*)$'# everything up to eol
166170
)
167171

172+
deloptvalueonly_source
173+
168174
# list of RawConfigParser methods able to change the instance
169175
_mutating_methods_= ("add_section","remove_section","remove_option","set")
170176

@@ -322,9 +328,11 @@ def string_decode(v):
322328
# end handle multi-line
323329
cursect[optname]=optval
324330
else:
325-
ifnote:
326-
e=cp.ParsingError(fpname)
327-
e.append(lineno,repr(line))
331+
# check if it's an option with no value - it's just ignored by git
332+
ifnotself.OPTVALUEONLY.match(line):
333+
ifnote:
334+
e=cp.ParsingError(fpname)
335+
e.append(lineno,repr(line))
328336
continue
329337
else:
330338
line=line.rstrip()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[color]
2+
ui
3+
[core]
4+
filemode = true

‎git/test/test_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,10 @@ def test_complex_aliases(self):
210210
self.assertEqual(w_config.get('alias','rbi'),'"!g() { git rebase -i origin/${1:-master} ; } ; g"')
211211
w_config.release()
212212
self.assertEqual(file_obj.getvalue(),self._to_memcache(fixture_path('.gitconfig')).getvalue())
213+
214+
deftest_empty_config_value(self):
215+
cr=GitConfigParser(fixture_path('git_config_with_empty_value'),read_only=True)
216+
217+
assertcr.get_value('core','filemode'),"Should read keys with values"
218+
219+
self.failUnlessRaises(cp.NoOptionError,cr.get_value,'color','ui')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp