Allow setting credentials and certificate in callback ctor
This allows for a less verbose way of setting one-liners as these callbacks.
This commit is contained in:
@@ -78,6 +78,21 @@ class RemoteCallbacks(object):
|
||||
in your class, which you can then pass to the network operations.
|
||||
"""
|
||||
|
||||
def __init__(self, credentials=None, certificate=None):
|
||||
"""Initialize some callbacks in-line
|
||||
|
||||
Use this constructor to provide credentials and certificate
|
||||
callbacks in-line, instead of defining your own class for these ones.
|
||||
|
||||
You can e.g. also pass in one of the credential objects as 'credentials'
|
||||
instead of creating a function which returns a hard-coded object.
|
||||
"""
|
||||
|
||||
if credentials is not None:
|
||||
self.credentials = credentials
|
||||
if certificate is not None:
|
||||
self.certificate = certificate
|
||||
|
||||
def sideband_progress(self, string):
|
||||
"""Progress output callback
|
||||
|
||||
|
@@ -514,13 +514,9 @@ class CloneRepositoryTest(utils.NoRepoTestCase):
|
||||
self.assertIsNotNone(repo.remotes["custom_remote"])
|
||||
|
||||
def test_clone_with_credentials(self):
|
||||
class MyCallbacks(pygit2.RemoteCallbacks):
|
||||
def __init__(self):
|
||||
self.credentials = pygit2.UserPass("libgit2", "libgit2")
|
||||
|
||||
repo = clone_repository(
|
||||
"https://bitbucket.org/libgit2/testgitrepository.git",
|
||||
self._temp_dir, callbacks=MyCallbacks())
|
||||
self._temp_dir, callbacks=pygit2.RemoteCallbacks(credentials=pygit2.UserPass("libgit2", "libgit2")))
|
||||
|
||||
self.assertFalse(repo.is_empty)
|
||||
|
||||
|
Reference in New Issue
Block a user