Improve error logging for pygit2 SSH-based remotes

If libgit2 is compiled without libssh2, an "Unsupported URL protocol"
GitError exception is raised. This commit catches this exception and, if
the credentials are a keypair (which means SSH auth), logs an meaningful
error message that will let the user know that libgit2 was probably not
compiled with libssh2.
This commit is contained in:
Erik Johnson 2015-04-17 12:49:54 -05:00
parent 3c91459de2
commit 9d394dfe46

View file

@ -1147,7 +1147,21 @@ def update():
except KeyError:
# No credentials configured for this repo
pass
fetch = origin.fetch()
try:
fetch = origin.fetch()
except pygit2.errors.GitError as exc:
# Using exc.__str__() here to avoid deprecation warning
# when referencing exc.message
if 'unsupported url protocol' in exc.__str__().lower() \
and isinstance(repo.get('credentials'),
pygit2.Keypair):
log.error(
'Unable to fetch SSH-based gitfs remote {0}. '
'libgit2 must be compiled with libssh2 to support '
'SSH authentication.'.format(repo['url'])
)
continue
raise
try:
# pygit2.Remote.fetch() returns a dict in pygit2 < 0.21.0
received_objects = fetch['received_objects']