-
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's not necessarily obvious how to perform a mirror, so add a recipe which tells what git does as well as provide example code of how to perform the same steps in pygit2.
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
********************************************************************** | ||
git-clone --mirror | ||
********************************************************************** | ||
|
||
git provides an argument to set up the repository as a mirror, which | ||
involves setting the refspec to one which copies all refs and a mirror | ||
option for push in the remote. | ||
|
||
.. code-block:: bash | ||
$> git clone --mirror https://github.com/libgit2/pygit2 | ||
.. code-block:: python | ||
def init_remote(repo, name, url): | ||
# Create the remote with a mirroring url | ||
remote = repo.remotes.create(name, url, "+refs/*:refs/*") | ||
# And set the configuration option to true for the push command | ||
mirror_var = "remote.{}.mirror".format(name) | ||
repo.config[mirror_var] = True | ||
# Return the remote, which pygit2 will use to perform the clone | ||
return remote | ||
print("Cloning pygit2 as mirror") | ||
pygit2.clone_repository("https://github.com/libgit2/pygit2", "pygit2.git", bare=True, | ||
remote=init_remote) |