From 5b50579790339f627f668ba4e1fc478bc3773fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 28 Apr 2015 13:30:31 +0200 Subject: [PATCH] Add a recipe for git clone --mirror 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. --- docs/recipes.rst | 1 + docs/recipes/git-clone-mirror.rst | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 docs/recipes/git-clone-mirror.rst diff --git a/docs/recipes.rst b/docs/recipes.rst index a5d769b65..919c0d701 100644 --- a/docs/recipes.rst +++ b/docs/recipes.rst @@ -22,5 +22,6 @@ Main porcelain commands git-log (Show commit logs.) git-show (Show various types of objects.) git-tag (Create, list, delete or verify a tag object signed with GPG.) + git clone --mirror (Clone with a mirroring configuration) .. _git man page: https://www.kernel.org/pub/software/scm/git/docs/git.html diff --git a/docs/recipes/git-clone-mirror.rst b/docs/recipes/git-clone-mirror.rst new file mode 100644 index 000000000..f8ea5caff --- /dev/null +++ b/docs/recipes/git-clone-mirror.rst @@ -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)