Trouble with ] in branch name
Hi everyone,
GitPython seems to have trouble with branch names that contain the ] character. It's probably a bad idea to use this character in a branch name, but it seems to be legal in principle, according to https://git-scm.com/docs/git-check-ref-format.
The problem can be reproduced as follows: Create a bare git repository with a branch named example] and run
from git.repo.base import Repo
Repo.clone_from("test-bare-repository", "test-cloned-repository", branch="example]")
I get the following debug output:
DEBUG:git.cmd:Popen(['git', 'clone', '-v', '--branch=example]', '--', 'test-bare-repository', 'test-cloned-repository'], cwd=***, universal_newlines=True, shell=None, istream=None)
The clone itself succeeds. However, when I navigate to the resulting cloned repository test-cloned-repository, I observe that the .git/config is faulty, since it contains the entry
[branch "example]
remote = origin
merge = refs/heads/example]
Consequently, git commands fail with fatal: bad config line 9 in file .git/config.
If I, instead, run the corresponding command from the console without using GitPython
git clone -v --branch=example] -- test-bare-repository test-cloned-repository
the clone works properly and the config line correctly reads
[branch "example]"]
These observations were made with Python 3.9.15, git version 2.34.1 and GitPython==3.1.30. So far, I couldn't spot the point in the GitPython code that causes this issue.
Thanks in advance and best regards Dominik
Thanks for the detailed report.
I think it happens in this line as it meddles with the URL of the remote. This is where it re-writes the config and does so wrongly. The reason for this most certainly is that GitPython abuses an INI parser, which is correct only superficially.
This bug is most certainly just the tip of the iceberg when it comes to correctness (or the lack thereof).
Good to know. Thanks for the answer!