本文整理汇总了Python中pygit2.clone_repository方法的典型用法代码示例。如果您正苦于以下问题:Python pygit2.clone_repository方法的具体用法?Python pygit2.clone_repository怎么用?Python pygit2.clone_repository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygit2
的用法示例。
在下文中一共展示了pygit2.clone_repository方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clone
# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import clone_repository [as 别名]
def clone(path_from, path_to, checkout_branch=None, bare=False):
""" Clone the git repo at the specified path to the specified location.
This method is meant to replace pygit2.clone_repository which for us
leaks file descriptors on large project leading to "Too many open files
error" which then prevent some tasks from completing.
:arg path_from: the path or url of the git repository to clone
:type path_from: str
:arg path_to: the path where the git repository should be cloned
:type path_to: str
:
"""
cmd = ["git", "clone", path_from, path_to]
if checkout_branch:
cmd.extend(["-b", checkout_branch])
if bare:
cmd.append("--bare")
run_command(cmd)
示例2: test_new_request_pull_empty_fork
# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import clone_repository [as 别名]
def test_new_request_pull_empty_fork(self, send_email):
""" Test the new_request_pull endpoint against an empty repo. """
send_email.return_value = True
self.test_fork_project()
tests.create_projects_git(
os.path.join(self.path, "requests"), bare=True
)
repo = pagure.lib.query.get_authorized_project(self.session, "test")
fork = pagure.lib.query.get_authorized_project(
self.session, "test", user="foo"
)
# Create a git repo to play with
gitrepo = os.path.join(self.path, "repos", "test.git")
repo = pygit2.init_repository(gitrepo, bare=True)
# Create a fork of this repo
newpath = tempfile.mkdtemp(prefix="pagure-fork-test")
gitrepo = os.path.join(self.path, "repos", "forks", "foo", "test.git")
new_repo = pygit2.clone_repository(gitrepo, newpath)
user = tests.FakeUser()
user.username = "foo"
with tests.user_set(self.app.application, user):
output = self.app.get(
"/fork/foo/test/diff/master..master", follow_redirects=True
)
self.assertEqual(output.status_code, 400)
self.assertIn(
"<p>Fork is empty, there are no commits to create a pull "
"request with</p>",
output.get_data(as_text=True),
)
shutil.rmtree(newpath)
示例3: _clone_and_top_commits
# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import clone_repository [as 别名]
def _clone_and_top_commits(folder, branch, branch_ref=False):
""" Clone the repository, checkout the specified branch and return
the top commit of that branch if there is one.
Returns the repo, the path to the clone and the top commit(s) in a tuple
or the repo, the path to the clone and the reference to the branch
object if branch_ref is True.
"""
if not os.path.exists(folder):
os.makedirs(folder)
brepo = pygit2.init_repository(folder, bare=True)
newfolder = tempfile.mkdtemp(prefix="pagure-tests")
repo = pygit2.clone_repository(folder, newfolder)
branch_ref_obj = None
if "origin/%s" % branch in repo.listall_branches(pygit2.GIT_BRANCH_ALL):
branch_ref_obj = pagure.lib.git.get_branch_ref(repo, branch)
repo.checkout(branch_ref_obj)
if branch_ref:
return (repo, newfolder, branch_ref_obj)
parents = []
commit = None
try:
if branch_ref_obj:
commit = repo[branch_ref_obj.peel().hex]
else:
commit = repo.revparse_single("HEAD")
except KeyError:
pass
if commit:
parents = [commit.oid.hex]
return (repo, newfolder, parents)
示例4: test_api_git_branches
# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import clone_repository [as 别名]
def test_api_git_branches(self):
""" Test the api_git_branches method of the flask api. """
# Create a git repo to add branches to
tests.create_projects(self.session)
repo_path = os.path.join(self.path, "repos", "test.git")
tests.add_content_git_repo(repo_path)
new_repo_path = tempfile.mkdtemp(prefix="pagure-api-git-branches-test")
clone_repo = pygit2.clone_repository(repo_path, new_repo_path)
# Create two other branches based on master
for branch in ["pats-win-49", "pats-win-51"]:
clone_repo.create_branch(branch, clone_repo.head.peel())
refname = "refs/heads/{0}:refs/heads/{0}".format(branch)
PagureRepo.push(clone_repo.remotes[0], refname)
# Check that the branches show up on the API
output = self.app.get("/api/0/test/git/branches")
# Delete the cloned git repo after the API call
shutil.rmtree(new_repo_path)
# Verify the API data
self.assertEqual(output.status_code, 200)
data = json.loads(output.get_data(as_text=True))
self.assertDictEqual(
data,
{
"branches": ["master", "pats-win-49", "pats-win-51"],
"total_branches": 3,
},
)
示例5: set_up_git_repo
# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import clone_repository [as 别名]
def set_up_git_repo(self, name="test"):
""" Set up the git repo to play with. """
# Create a git repo to play with
gitrepo = os.path.join(self.path, "repos", "%s.git" % name)
repo = pygit2.init_repository(gitrepo, bare=True)
newpath = tempfile.mkdtemp(prefix="pagure-other-test")
repopath = os.path.join(newpath, "test")
clone_repo = pygit2.clone_repository(gitrepo, repopath)
# Create a file in that git repo
with open(os.path.join(repopath, "sources"), "w") as stream:
stream.write("foo\n bar")
clone_repo.index.add("sources")
clone_repo.index.write()
# Commits the files added
tree = clone_repo.index.write_tree()
author = pygit2.Signature("Alice Author", "alice@authors.tld")
committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
clone_repo.create_commit(
"refs/heads/master", # the name of the reference to update
author,
committer,
"Add sources file for testing",
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
[],
)
refname = "refs/heads/master"
ori_remote = clone_repo.remotes[0]
PagureRepo.push(ori_remote, refname)
示例6: clone_project
# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import clone_repository [as 别名]
def clone_project(self, repo_url, repo_path, branch):
repo = False
try:
repo = clone_repository(
repo_url, repo_path, checkout_branch=branch)
assert bool(repo), \
'Unknown error when downloading {}'.format(repo_url)
except Exception as e:
error_event = ErrorEvent(e.message)
self.onError.fire(error_event)
return repo
示例7: clone
# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import clone_repository [as 别名]
def clone(cls, url, folder):
'''Clone the repository'''
pygit2.clone_repository(url, folder)
示例8: create_repo
# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import clone_repository [as 别名]
def create_repo(repo_path, remote_url, creds):
if os.path.exists(repo_path):
logger.info('Cleaning up repo path...')
shutil.rmtree(repo_path)
repo = clone_repository(remote_url, repo_path, callbacks=creds)
return repo
示例9: test_new_request_pull_empty_repo
# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import clone_repository [as 别名]
def test_new_request_pull_empty_repo(self, send_email):
""" Test the new_request_pull endpoint against an empty repo. """
send_email.return_value = True
self.test_fork_project()
tests.create_projects_git(
os.path.join(self.path, "requests"), bare=True
)
repo = pagure.lib.query.get_authorized_project(self.session, "test")
fork = pagure.lib.query.get_authorized_project(
self.session, "test", user="foo"
)
# Create a git repo to play with
gitrepo = os.path.join(self.path, "repos", "test.git")
repo = pygit2.init_repository(gitrepo, bare=True)
# Create a fork of this repo
newpath = tempfile.mkdtemp(prefix="pagure-fork-test")
gitrepo = os.path.join(self.path, "repos", "forks", "foo", "test.git")
new_repo = pygit2.clone_repository(gitrepo, newpath)
user = tests.FakeUser()
user.username = "foo"
with tests.user_set(self.app.application, user):
output = self.app.get(
"/fork/foo/test/diff/master..feature", follow_redirects=True
)
self.assertEqual(output.status_code, 400)
self.assertIn(
"<p>Fork is empty, there are no commits to create a pull "
"request with</p>",
output.get_data(as_text=True),
)
output = self.app.get("/test/new_issue")
csrf_token = self.get_csrf(output=output)
data = {"csrf_token": csrf_token, "title": "foo bar PR"}
output = self.app.post(
"/test/diff/master..feature", data=data, follow_redirects=True
)
self.assertEqual(output.status_code, 400)
self.assertIn(
"<p>Fork is empty, there are no commits to create a pull "
"request with</p>",
output.get_data(as_text=True),
)
shutil.rmtree(newpath)
示例10: set_up_git_repo
# 需要导入模块: import pygit2 [as 别名]
# 或者: from pygit2 import clone_repository [as 别名]
def set_up_git_repo(self):
""" Set up the git repo to play with. """
# Create a git repo to play with
gitrepo = os.path.join(self.path, "repos", "test.git")
repo = pygit2.init_repository(gitrepo, bare=True)
newpath = tempfile.mkdtemp(prefix="pagure-other-test")
repopath = os.path.join(newpath, "test")
clone_repo = pygit2.clone_repository(gitrepo, repopath)
# Create a file in that git repo
with open(os.path.join(repopath, "sources"), "w") as stream:
stream.write("foo\n bar")
clone_repo.index.add("sources")
clone_repo.index.write()
# Commits the files added
tree = clone_repo.index.write_tree()
author = pygit2.Signature("Alice Author", "alice@authors.tld")
committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
clone_repo.create_commit(
"refs/heads/feature", # the name of the reference to update
author,
committer,
"Add sources file for testing",
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
[],
)
feature_branch = clone_repo.lookup_branch("feature")
first_commit = feature_branch.peel().hex
# Second commit
with open(os.path.join(repopath, ".gitignore"), "w") as stream:
stream.write("*~")
clone_repo.index.add(".gitignore")
clone_repo.index.write()
tree = clone_repo.index.write_tree()
author = pygit2.Signature("Alice Author", "alice@authors.tld")
committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")
clone_repo.create_commit(
"refs/heads/feature",
author,
committer,
"Add .gitignore file for testing",
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
[first_commit],
)
refname = "refs/heads/feature"
ori_remote = clone_repo.remotes[0]
PagureRepo.push(ori_remote, refname)
shutil.rmtree(newpath)