Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble with ] in branch name #1539

Open
DominikVollandTNG opened this issue Jan 13, 2023 · 2 comments
Open

Trouble with ] in branch name #1539

DominikVollandTNG opened this issue Jan 13, 2023 · 2 comments

Comments

@DominikVollandTNG
Copy link

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

@Byron
Copy link
Member

Byron commented Jan 14, 2023

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).

@DominikVollandTNG
Copy link
Author

Good to know. Thanks for the answer!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants