Repository navigation
Commit ba5fc18
committed
fix(commit): end commit headers only at an empty line
`Commit._deserialize` read the headers after `committer` with
`readline().strip()` and stopped at the first line that was empty after
stripping. Git ends the header block only at a truly empty line, so a
header line holding only whitespace (`\r`, a bare continuation space,
`\t`) ended the headers in GitPython but not in git. Everything up to
the real blank line was then returned as part of `Commit.message`, and
any `encoding` or `gpgsig` header after that line was missed.
Commit headers are chosen by whoever wrote the commit. This object is
accepted by `git hash-object -t commit -w` and `git fsck --strict`
(git 2.50.1):
tree <tree>
author A <a@x> 1700000000 +0000
committer A <a@x> 1700000000 +0000
x-note a
\r
Approved-by: Mallory <m@evil>
real subject
`git log --format=%B` shows `real subject`, while GitPython returned
`Approved-by: Mallory <m@evil>\n\nreal subject\n` as the message and
the forged line as `summary`; a co-author trailer placed there the same
way is listed by `co_authors`. With an
`encoding ISO-8859-1` header after a ` ` line, git decoded the author
and message as Latin-1, but GitPython kept UTF-8 and showed the
`encoding` line as message text.
The loop now ends only at an empty line or the end of the stream, and
strips only trailing whitespace before it matches header names. Leading
whitespace is no longer stripped, so a continuation line such as
` encoding X` is not read as a header of its own. Commits whose headers
end at a plain `\n` parse exactly as before.
Adds `test_deserialization_headers_end_at_empty_line` to
`test/test_commit.py`. It fails before this change and passes after.
`test/test_commit.py` passes (43 tests). In the full suite, 7 tests fail
in this environment; they fail the same way without this change.
`ruff check`, `ruff format --check` and `mypy` are clean on the changed
files.1 parent ccc4811 commit ba5fc18
2 files changed
Lines changed: 31 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
895 | | - | |
896 | | - | |
897 | | - | |
898 | | - | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
899 | 902 | | |
900 | 903 | | |
901 | 904 | | |
| |||
917 | 920 | | |
918 | 921 | | |
919 | 922 | | |
920 | | - | |
| 923 | + | |
921 | 924 | | |
922 | 925 | | |
923 | 926 | | |
924 | 927 | | |
925 | 928 | | |
926 | 929 | | |
927 | 930 | | |
928 | | - | |
| 931 | + | |
929 | 932 | | |
930 | 933 | | |
931 | 934 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
513 | 513 | | |
514 | 514 | | |
515 | 515 | | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
516 | 538 | | |
517 | 539 | | |
518 | 540 | | |
| |||
0 commit comments