本文整理汇总了Python中pygit2.Repository.clone_from方法的典型用法代码示例。如果您正苦于以下问题:Python Repository.clone_from方法的具体用法?Python Repository.clone_from怎么用?Python Repository.clone_from使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygit2.Repository
的用法示例。
在下文中一共展示了Repository.clone_from方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import clone_from [as 别名]
def __init__(self, repo_obj, cache='/tmp', languages=None, branch='master'):
# local import to avoid a circular import
from analysis.models import Branch
self.repo_obj = repo_obj
if languages is None:
languages = ["python"]
self.languages = languages
self.branch = branch
repo_url = self.repo_obj.url
repo_dir = os.path.join(cache, quote(repo_url))
try:
self.repo = Repo(repo_dir)
origin = self.repo.remotes.origin
try:
origin.fetch('all')
origin.pull(self.branch)
except AssertionError as e:
# triggers when trying to pull on a repo that is up to date already
print e
print "FAILED TO PULL"
pass
except GitError:
self.repo = Repo.clone_from(repo_url, repo_dir)
branch_obj = Branch.objects.filter(repository=repo_obj, name=self.branch)[:1]
if not branch_obj:
branch_obj = Branch(repository=repo_obj, name=self.branch)
# TODO branch last analyzed
branch_obj.save()
else:
branch_obj = branch_obj[0]
self.branch_obj = branch_obj