Skip to content

Commit f6f43e8

Browse files
committed
Allow setting credentials and certificate in callback ctor
This allows for a less verbose way of setting one-liners as these callbacks.
1 parent 31b5f20 commit f6f43e8

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pygit2/remote.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ class RemoteCallbacks(object):
7878
in your class, which you can then pass to the network operations.
7979
"""
8080

81+
def __init__(self, credentials=None, certificate=None):
82+
"""Initialize some callbacks in-line
83+
84+
You can use this constructor to provide credentials and certificate
85+
callbacks in-line, instead of defining your own class for these ones.
86+
"""
87+
88+
if credentials is not None:
89+
self.credentials = credentials
90+
if certificate is not None:
91+
self.certificate = certificate
92+
8193
def sideband_progress(self, string):
8294
"""Progress output callback
8395

test/test_repository.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,13 +514,9 @@ def create_remote(repo, name, url):
514514
self.assertIsNotNone(repo.remotes["custom_remote"])
515515

516516
def test_clone_with_credentials(self):
517-
class MyCallbacks(pygit2.RemoteCallbacks):
518-
def __init__(self):
519-
self.credentials = pygit2.UserPass("libgit2", "libgit2")
520-
521517
repo = clone_repository(
522518
"https://bitbucket.org/libgit2/testgitrepository.git",
523-
self._temp_dir, callbacks=MyCallbacks())
519+
self._temp_dir, callbacks=pygit2.RemoteCallbacks(credentials=pygit2.UserPass("libgit2", "libgit2")))
524520

525521
self.assertFalse(repo.is_empty)
526522

0 commit comments

Comments
 (0)