gitpython-developers/GitPython — Issue #44: Incorrect handling of backslashes in Git configuration
Author: ereOn
Created: 2012-02-07 15:02:54+00:00
State: open

Steps to reproduce the issue:

import git
config = git.Repo().config_writer()
config.add_section('test')
config.set_value('test', 'test', r'some\data')

Now if you try to read this value using a regular (non Python) `git config`, Git complains that the configuration file is invalid:

fatal: bad config file line 11 in .git/config

Indeed, if you open `.git/config` you can see that the value is written as:

[test]
test = some\data

While the [`git-config` configuration]() states that:

> String values may be entirely or partially enclosed in double quotes. You need to enclose variable values in double quotes if you want to preserve leading or trailing whitespace, or if the variable value contains comment characters (i.e. it contains # or ;). Double quote " and backslash \ characters in variable values must be escaped: use \" for " and \\ for \.

That is, the backslashes are not escaped in the configuration file.

This also cause issues regarding the reading, where values are not un-escaped.