File: git-clone-ssh.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 (31 lines) | stat: -rw-r--r-- 1,224 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.enums.CredentialType.USERNAME:
                return pygit2.Username("git")
            elif allowed_types & pygit2.enums.CredentialType.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)