GitHubJacksonized

fix: join backslash line continuations when reading config values by nkbeast · Pull Request #2227 · gitpython-developers/GitPython

@nkbeast
nkbeast force-pushed the fix-config-backslash-continuation branch from 1f4913b to 22b4db5 Compare September 3, 2026 21:06
git config joins an unquoted value that ends in a backslash with the
next line: the backslash and the newline are removed and the next line
is appended verbatim, so 'k = line1\' followed by ' line2' reads back
as 'line1 line2'. GitPython only implemented multi-line values for
quoted strings; for unquoted values the continuation line was silently
dropped, truncating whatever was stored in the config.

Read the continuation inside _read and join it, chaining across lines
that themselves end in a backslash. An even number of trailing
backslashes is an escaped one, so the value ends there; a single
backslash right at end-of-file is dropped, matching git. Verified
against git itself for every case covered by the new tests.
@nkbeast
nkbeast force-pushed the fix-config-backslash-continuation branch from 22b4db5 to 075a664 Compare September 3, 2026 21:10
Byron and others added 2 commits September 4, 2026 06:26
<!-- agent -->
Git treats # and ; outside quotes as the start of a comment. A trailing
backslash in that ignored text therefore cannot continue the value.

The continuation loop counted trailing slashes without lexical context, so
it consumed the next option and a later writable flush silently dropped that
setting.

- Track quote and escape state while checking the accumulated value.
- Stop continuation scanning at an unquoted comment.
- Cover preservation of the following option across a writable flush.

Assisted-by: GPT 5.6
Co-authored-by: GPT 5.6 <[email protected]>
Git removes each backslash-newline pair before parsing the resulting logical
value. Appending physical lines after processing only the first line left
trailing whitespace, comments, quotes, and recognized escapes literal.

That divergence returned values unlike git config and could preserve comment
text as configuration data.

- Accumulate continuation text before parsing it.
- Apply whitespace, comment, quote, and escape handling once to the complete value.
- Cover each affected syntax form with Git-compatible expectations.

Assisted-by: GPT 5.6
Co-authored-by: GPT 5.6 <[email protected]>
@Byron
Byron merged commit 9ebf8b6 into gitpython-developers:main Sep 4, 2026
53 checks passed

Originally published at github.com. Every curse word you see was added by the Samuel L. Jacksonizer, a parody site. Not affiliated with Samuel L. Jackson or github.com.