libgit2 / pygit2

Python bindings for libgit2
https://www.pygit2.org/
Other
1.59k stars 383 forks source link

Fix garbled mirror configuration in recipe for `git clone --mirror` #1072

Closed cjolowicz closed 3 years ago

cjolowicz commented 3 years ago

The documentation contains a recipe for how to emulate git clone --mirror. In the example code, the init_remote callback constructs the mirror configuration passing name to str.format. However, the callback receives the name (and url) as bytes, so str.format would return something like this:

"remote.b'origin'.mirror"

This commit fixes the code example by decoding name when used with str.format.

The invocation of repo.remotes.create in the same example works fine as is, because that function invokes to_bytes on its arguments, and to_bytes is a noop when passed bytes.