File: git-clone-mirror.rst

package info (click to toggle)
python-pygit2 1.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,720 kB
  • sloc: ansic: 12,584; python: 9,337; sh: 205; makefile: 26
file content (26 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
**********************************************************************
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 = f"remote.{name.decode()}.mirror"
        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)