From 4588ec7272e2d27669f26640177ab1a95efe4b9e Mon Sep 17 00:00:00 2001 From: lrossett Date: May 25 2021 00:51:28 +0000 Subject: using git.Repo instead of git.cmd --- diff --git a/src/centpkg/__init__.py b/src/centpkg/__init__.py index 588fc23..e311c9a 100644 --- a/src/centpkg/__init__.py +++ b/src/centpkg/__init__.py @@ -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\d+[s]?)-sig-(?P\w+)-?(?P\w+)?-?(?P\w+)?' distrobranchre = r'c(?P\d+)-?(?P\w+)?' oldbranchre = r'(?P\w+)(?P\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): """ diff --git a/tests/test_distgit.py b/tests/test_distgit.py index 5b1ad05..96142ff 100644 --- a/tests/test_distgit.py +++ b/tests/test_distgit.py @@ -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()) \ No newline at end of file