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

Add a recipe for git clone --mirror #527

Merged
merged 1 commit into from
Apr 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ Main porcelain commands
git-log (Show commit logs.) <recipes/git-log>
git-show (Show various types of objects.) <recipes/git-show>
git-tag (Create, list, delete or verify a tag object signed with GPG.) <recipes/git-tag>
git clone --mirror (Clone with a mirroring configuration) <recipes/git-clone-mirror>

.. _git man page: https://www.kernel.org/pub/software/scm/git/docs/git.html
25 changes: 25 additions & 0 deletions docs/recipes/git-clone-mirror.rst
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)