Skip to content

Commit 6925345

Browse files
committed
Handle indented comments in git config files
It's perfectly valid for a git config file to contain comments inside sections, e.g.: [core] # This is a shared repository sharedRepository = true The git tools all parse this fine while GitPython was choking on it.
1 parent 35bceb1 commit 6925345

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

git/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,14 @@ def _read(self, fp, fpname):
205205
optname = None
206206
lineno = 0
207207
e = None # None, or an exception
208+
comment_re = re.compile('^\s*[#;]')
208209
while True:
209210
line = fp.readline()
210211
if not line:
211212
break
212213
lineno = lineno + 1
213214
# comment or blank line?
214-
if line.strip() == '' or line[0] in '#;':
215+
if line.strip() == '' or comment_re.match(line):
215216
continue
216217
if line.split(None, 1)[0].lower() == 'rem' and line[0] in "rR":
217218
# no leading whitespace

0 commit comments

Comments
 (0)