Skip to content

fix: join backslash line continuations when reading config values - #2227

Merged
Byron merged 3 commits into
gitpython-developers:mainfrom
nkbeast:fix-config-backslash-continuation
Sep 4, 2026
Merged

Byron merged 3 commits into
gitpython-developers:mainfrom
nkbeast:fix-config-backslash-continuation

Conversation

@nkbeast

@nkbeast nkbeast commented Sep 3, 2026

Copy link
Copy Markdown

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. Reproducing with git itself:

$ printf '[a]\n\tk = line1\\\n line2\n' > g.cfg
$ git config -f g.cfg a.k
line1 line2

GitPython only implemented multi-line values for quoted strings. For unquoted values the continuation line was silently dropped — GitConfigParser read back line1\ and the line2 content vanished, truncating whatever the user had stored (aliases, hook commands, any hand-edited multi-line value).

The fix reads the continuation inside _read and joins it, chaining across lines that themselves end in a backslash, with the exact rules git uses:

  • a single trailing backslash → continuation, next line appended verbatim (leading whitespace included)
  • an even number of trailing backslashes → an escaped one, value ends there (val\\\\ stays val\\\\)
  • a lone backslash right at end-of-file → dropped

All five cases are asserted against git's own output in the new test.