| |
@@ -19,22 +19,32 @@
|
| |
import re
|
| |
import warnings
|
| |
|
| |
+ import git
|
| |
from pyrpkg import Commands, rpkgError
|
| |
+ from pyrpkg.utils import cached_property
|
| |
+
|
| |
# doc/centpkg_man_page.py uses the 'cli' import
|
| |
from . import cli # noqa
|
| |
from .lookaside import StreamLookasideCache, SIGLookasideCache
|
| |
- from pyrpkg.utils import cached_property
|
| |
+
|
| |
+
|
| |
+ _DEFAULT_VERSION = '9'
|
| |
|
| |
|
| |
class DistGitDirectory(object):
|
| |
|
| |
signame = None
|
| |
- centosversion = None
|
| |
+ centosversion = _DEFAULT_VERSION
|
| |
projectname = None
|
| |
releasename = None
|
| |
distrobranch = False
|
| |
+ repo = None
|
| |
+ git_origin_substr = 'git@gitlab.com/redhat/centos-stream'
|
| |
|
| |
- def __init__(self, branchtext):
|
| |
+ def __init__(self, branchtext, repo_path=None):
|
| |
+ if 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)'
|
| |
@@ -65,7 +75,39 @@
|
| |
warnings.warn("This branch is deprecated and will be removed soon",
|
| |
DeprecationWarning)
|
| |
else:
|
| |
- raise ValueError("Branchname: {0} is not valid".format(branchtext))
|
| |
+ if not self.is_fork():
|
| |
+ raise ValueError("Branchname: {0} is not valid".format(branchtext))
|
| |
+ else:
|
| |
+ self.distrobranch = True
|
| |
+ self.signame = 'centos'
|
| |
+ self.projectname = self.get_origin().split('_')[-1].replace('.git', '')
|
| |
+
|
| |
+ warnings.warn('Remote "origin" was detected as a fork, ignoring branch name checking')
|
| |
+
|
| |
+ def get_origin(self):
|
| |
+ if self.repo is None:
|
| |
+ return ''
|
| |
+ 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):
|
| |
+ """
|
| |
+ Check if origin remote repository is using a fork url.
|
| |
+
|
| |
+ Returns
|
| |
+ bool
|
| |
+ A boolean flag indicating if origin remote url is using
|
| |
+ a forked repository url.
|
| |
+ """
|
| |
+ # git+ssh://git@gitlab.com/redhat/centos-stream/rpms/binutils.git
|
| |
+ if self.repo is None:
|
| |
+ return False
|
| |
+ return self.git_origin_substr not in self.get_origin()
|
| |
+
|
| |
|
| |
@property
|
| |
def target(self):
|
| |
@@ -105,7 +147,7 @@
|
| |
|
| |
@property
|
| |
def distgitdir(self):
|
| |
- return DistGitDirectory(self.branch_merge)
|
| |
+ return DistGitDirectory(self.branch_merge, repo_path=self.path)
|
| |
|
| |
@cached_property
|
| |
def lookasidecache(self):
|
| |
fixes #19
Ignores the branch naming pattern if origin url is not a upstream one.