File: git-clone-ssh.rst

package info (click to toggle)
python-pygit2 1.4.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,328 kB
  • sloc: ansic: 11,016; python: 5,943; sh: 275; makefile: 19
file content (31 lines) | stat: -rw-r--r-- 1,236 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
27
28
29
30
31
**********************************************************************
git-clone ssh://git@example.com
**********************************************************************

Example for cloning a git repository over ssh.

.. code-block:: bash

   $ git clone git@example.com

.. code-block:: python

    class MyRemoteCallbacks(pygit2.RemoteCallbacks):

        def credentials(self, url, username_from_url, allowed_types):
            if allowed_types & pygit2.credentials.GIT_CREDENTIAL_USERNAME:
                return pygit2.Username("git")
            elif allowed_types & pygit2.credentials.GIT_CREDENTIAL_SSH_KEY:
                return pygit2.Keypair("git", "id_rsa.pub", "id_rsa", "")
            else:
                return None

    print("Cloning pygit2 over ssh")
    pygit2.clone_repository("ssh://github.com/libgit2/pygit2", "pygit2.git",
                            callbacks=MyRemoteCallbacks())

    print("Cloning pygit2 over ssh with the username in the URL")
    keypair = pygit2.Keypair("git", "id_rsa.pub", "id_rsa", "")
    callbacks = pygit2.RemoteCallbacks(credentials=keypair)
    pygit2.clone_repository("ssh://git@github.com/libgit2/pygit2", "pygit2.git",
                            callbacks=callbacks)