using git.Repo instead of git.cmd

This commit is contained in:
lrossett 2021-05-06 12:55:41 -03:00 committed by carlwgeorge
parent 4d28cf158c
commit 4588ec7272
2 changed files with 15 additions and 5 deletions

View file

@ -43,7 +43,8 @@ class DistGitDirectory(object):
def __init__(self, branchtext, repo_path=None):
if repo_path:
self.repo = git.cmd.Git(repo_path)
# self.repo = git.cmd.Git(repo_path)
self.repo = git.repo.Repo(repo_path)
sigtobranchre = r'c(?P<centosversion>\d+[s]?)-sig-(?P<signame>\w+)-?(?P<projectname>\w+)?-?(?P<releasename>\w+)?'
distrobranchre = r'c(?P<centosversion>\d+)-?(?P<projectname>\w+)?'
oldbranchre = r'(?P<signame>\w+)(?P<centosversion>\d)'
@ -86,7 +87,12 @@ class DistGitDirectory(object):
def get_origin(self):
if self.repo is None:
return ''
return self.repo.execute('git config --get remote.origin.url'.split())
if 'origin' not in self.repo.remotes:
return ''
urls = [u for u in self.repo.remotes['origin'].urls]
if len(urls) == 0:
return ''
return urls[0]
def is_fork(self):
"""

View file

@ -1,6 +1,8 @@
import unittest
import unittest.mock
import git
from .mixins import CatchWarningsMixin
from centpkg import DistGitDirectory
from centpkg import git as centpkg_git
@ -192,12 +194,14 @@ class TestIsFork(unittest.TestCase):
d = DistGitDirectory(self.branchstring)
self.assertFalse(d.is_fork())
@unittest.mock.patch.object(centpkg_git.cmd.Git, 'execute', new=lambda s, c: 'git@gitlab.com:user/centos_rpms_binutils.git')
@unittest.mock.patch.object(centpkg_git.repo.Repo, 'remotes', new=dict(origin=type('Remote', (object,), {'urls': ['ssh://git@git.centos.org/forks/lrossett/centos/centpkg.git']})))
@unittest.mock.patch.object(centpkg_git.repo.Repo, '__init__', new=lambda s, p: None)
def test_fork_url(self):
d = DistGitDirectory(self.branchstring, 'binutils')
self.assertTrue(d.is_fork())
@unittest.mock.patch.object(centpkg_git.cmd.Git, 'execute', new=lambda s, c: 'git+ssh://git@gitlab.com/redhat/centos-stream/rpms/binutils.git')
@unittest.mock.patch.object(centpkg_git.repo.Repo, 'remotes', new=dict(origin=type('Remote', (object,), {'urls': ['git+ssh://git@gitlab.com/redhat/centos-stream/rpms/binutils.git']})))
@unittest.mock.patch.object(centpkg_git.repo.Repo, '__init__', new=lambda s, p: None)
def test_upstream_url(self):
d = DistGitDirectory(self.branchstring, 'binutils')
self.assertFalse(d.is_fork())