From f92a991468a2cc0dcf4892b7dba409f5fd91f82e Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Oct 09 2015 10:20:40 +0000 Subject: Fix pygit2 version comparison for pygit2 >= 0.23. --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 1a9726c..cdc9c5b 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -32,6 +32,13 @@ from pagure.lib.repo import PagureRepo # pylint: disable=R0913,E1101,R0914 +def get_pygit2_version(): + ''' Return pygit2 version as a tuple of integers. + This is needed for correct version comparison. + ''' + return tuple([int(i) for i in pygit2.__version__.split('.')]) + + def commit_to_patch(repo_obj, commits): ''' For a given commit (PyGit2 commit object) of a specified git repo, returns a string representation of the changes the commit did in a diff --git a/pagure/lib/repo.py b/pagure/lib/repo.py index c8a0661..2db6ba5 100644 --- a/pagure/lib/repo.py +++ b/pagure/lib/repo.py @@ -13,6 +13,7 @@ import pygit2 import pagure import pagure.exceptions +import pagure.lib.git class PagureRepo(pygit2.Repository): @@ -24,7 +25,8 @@ class PagureRepo(pygit2.Repository): @staticmethod def push(remote, refname): """ Push the given reference to the specified remote. """ - if pygit2.__version__.startswith('0.22'): + pygit2_version = pagure.lib.git.get_pygit2_version() + if pygit2_version >= (0, 22): remote.push([refname]) else: remote.push(refname)