fix: ignore comments after implicit boolean config keys · gitpython-developers/GitPython@42566c6 · GitHub
Skip to content

Commit 42566c6

Browse files
codexByron
authored andcommitted
fix: ignore comments after implicit boolean config keys
Bare entries such as "enabled # comment" and "enabled ; comment" retained the comment in the option name. getboolean("flag", "enabled") therefore raised NoOptionError, and an unrelated write emitted the malformed key again. An equals sign or colon inside the comment also made the parser mistake the entry for an assignment. Stop the shared option-name expression at either comment marker. Both the assignment and valueless patterns then extract only the bare name, preserving its None representation, true boolean value, and bare syntax on write-back. Quoted values continue through the existing value parser. Add a round-trip regression covering both comment markers with spaces, tabs, or no separator, including equals signs and colons in comments. All six cases failed with NoOptionError before the fix. Check the parsed name and boolean, exact output after an unrelated edit, and the boolean read back by both GitPython and git config. Git reference: checkout 1630431f326e15fcde608827b5ff38422528eb59, Documentation/config.adoc and config.c:get_value. Despite the general comment rule in the documentation, that parser and Git 2.50.1 (Apple Git-155) reject comments after bare keys. Accepting them is the requested GitPython behavior; the normalized bare-key output is accepted by Git. Validation on Python 3.12.14: 42 configuration tests and six regression subtests passed, with two existing skips. Ruff lint and formatting, mypy (46 source files), basedpyright, and git diff --check passed.
1 parent d171e34 commit 42566c6

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

git/config.py

Lines changed: 1 addition & 1 deletion

test/test_config.py

Lines changed: 30 additions & 0 deletions

0 commit comments

Comments
 (0)