From 88d54a58ef783282b4a522addda02e18aa31f1f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=98yvind=20Karlsen?= Date: Fri, 22 Jul 2016 16:48:40 +0200 Subject: add support for cloning properly setup git-svn repos from github --- MgaRepo/GitHub.py | 20 +++++++++++++++++++- MgaRepo/commands/github.py | 5 ++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/MgaRepo/GitHub.py b/MgaRepo/GitHub.py index c077f7b..71f53d6 100644 --- a/MgaRepo/GitHub.py +++ b/MgaRepo/GitHub.py @@ -1,5 +1,6 @@ from MgaRepo import Error, config from MgaRepo.rpmutil import detectVCS, get_pkg_tag, clone +from MgaRepo.util import execcmd from MgaRepo import layout from MgaRepo.git import GIT from MgaRepo.svn import SVN @@ -58,7 +59,7 @@ class GitHub(object): else: raise Error(output) - status, output = vcs.push(repository.full_name, "master", show=True) + status, output = vcs.push("--mirror", repository.full_name, show=True) if status == 0: print("Success!") return True @@ -69,3 +70,20 @@ class GitHub(object): else: raise Error("GitHub repository already exists at " + repository.html_url) raise Error("GitHub import failed...") + + def clone_repository(self, pkgname, target=None): + if not target: + target = pkgname + repository = self.repository_exists(pkgname) + if repository: + svnurl = layout.checkout_url(layout.package_url(pkgname)) + if repository.permissions: + giturl = repository.ssh_url + else: + giturl = repository.git_url + execcmd(("git", "clone", "--mirror", giturl, os.path.join(target, ".git")), show=True) + git_svn = GIT(path=target, url=svnurl) + git_svn.init(svnurl, pkgname, branch="master", fullnames=True) + + return True + raise Error("Repository %s doesn't exist!" % (self._organization.login+"/"+pkgname)) diff --git a/MgaRepo/commands/github.py b/MgaRepo/commands/github.py index c2fd188..3d600bc 100644 --- a/MgaRepo/commands/github.py +++ b/MgaRepo/commands/github.py @@ -17,6 +17,9 @@ Examples: mgarepo github import existingpkg mgarepo github import svn://svn.mageia.org/svn/packages/cauldron/existingpkg """ +def github_clone(pkg, **kwargs): + github = GitHub() + github.clone_repository(pkg) def github_import(target=".", **kwargs): github = GitHub() @@ -34,7 +37,7 @@ def parse_options(): opts.func = globals().get("github_"+args[0], None) if args[0] == "import": opts.target = args[1] - elif args[0] == "delete": + elif args[0] == "delete" or args[0] == "clone": opts.pkg = args[1] else: raise Error("invalid arguments: %s" % str(args)) -- cgit v1.2.1