Skip to content

fix: skip a UTF-8 BOM when reading motherf*ckin' config files - #2249

Merged
Byron merged 1 commit into
gitpython-developers:mainfrom
geek-alpha:config-utf8-bom
Sep 21, 2026
Merged

Byron merged 1 commit into
gitpython-developers:mainfrom
geek-alpha:config-utf8-bom

Conversation

@geek-alpha

@geek-alpha geek-alpha commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

git skips a f*ckin' UTF-8 BOM at the start of a muthaf*ckin' config file. GitConfigParser raised MissingSectionHeaderError instead, because the decoded BOM became part of the first line, and that line then no longer matched a f*ckin' section header.

  • Skip the BOM bytes when reading the motherf*ckin' first line of a config file.
  • Add a f*ckin' regression test that fails without the goddamn change.

Why this is a bug and not malformed input

git reads such a muthaf*ckin' file fine, so GitPython disagreeing with git here is the bug. The error is also hard to act on: the damn file clearly starts with [core], yet the damn message says it contains no section headers.

Validation

git 2.47.3, file starting with the three BOM bytes EF BB BF:

$ git config -f bom.cfg --list
core.bare=true
$ echo $?
0

GitPython before the change:

configparser.MissingSectionHeaderError: File contains no section headers.
file: 'bom.config', line: 1
'\ufeff[core]\n'

After the change get_value("core", "bare") is True, matching git. A BOM file reached through include.path is read the same as git as well (user.name=bom-inc).

Test runs:

  • pytest test/test_config.py -o addopts= -q -> 48 passed, 2 skipped, 20 subtests passed
  • pytest test/ -o addopts= -q -> 988 passed, 82 skipped, 1 xfailed
  • ruff check / ruff format --check on both files -> clean

AI agent disclosure

Per CONTRIBUTING ("Prevent agent impersonation"): this muthaf*ckin' PR was prepared by an motherf*ckin' AI
agent (Battle Phoenix) driving the geek-alpha account. The account owner reviewed
and approved the damn change, the test and the evidence above.

git ignores a UTF-8 BOM at the start of a config file, so a file written by a
Windows editor still parses. GitConfigParser raised MissingSectionHeaderError
instead, because the BOM was decoded into the first line, which then no longer
matched a section header.

Evidence on git 2.47.3: `git config -f bom.cfg --list` prints core.bare=true
for a file starting with the three BOM bytes, while GitPython raised
MissingSectionHeaderError. With this change both read the same values, also
when the BOM file is pulled in through include.path.

The new test fails without the change.

@Byron Byron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this f*ckin' comment

The reason will be displayed to describe this motherf*ckin' comment to others. Learn more.

Great, thanks!

@Byron
Byron merged commit a54d159 into gitpython-developers:main Sep 21, 2026
47 checks passed
Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

2 participants