本文整理汇总了Python中pagure.lib.repo.PagureRepo.push方法的典型用法代码示例。如果您正苦于以下问题:Python PagureRepo.push方法的具体用法?Python PagureRepo.push怎么用?Python PagureRepo.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pagure.lib.repo.PagureRepo
的用法示例。
在下文中一共展示了PagureRepo.push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_file_git_repo
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def remove_file_git_repo(folder, filename, branch="master"):
""" Delete the specified file on the give git repo and branch. """
repo, newfolder, parents = _clone_and_top_commits(folder, branch)
# Remove file
repo.index.remove(filename)
# Write the change and commit it
tree = repo.index.write_tree()
author = pygit2.Signature("Alice Author", "[email protected]")
committer = pygit2.Signature("Cecil Committer", "[email protected]")
branch_ref = "refs/heads/%s" % branch
repo.create_commit(
branch_ref, # the name of the reference to update
author,
committer,
"Remove file %s" % filename,
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
parents,
)
# Push to origin
ori_remote = repo.remotes[0]
PagureRepo.push(ori_remote, "%s:%s" % (branch_ref, branch_ref))
shutil.rmtree(newfolder)
示例2: set_up_git_repo
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [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(tests.HERE, "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", "[email protected]")
committer = pygit2.Signature("Cecil Committer", "[email protected]")
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.get_object().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", "[email protected]")
committer = pygit2.Signature("Cecil Committer", "[email protected]")
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)
示例3: set_up_git_repo
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [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", "[email protected]")
committer = pygit2.Signature("Cecil Committer", "[email protected]")
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)
示例4: add_binary_git_repo
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def add_binary_git_repo(folder, filename):
""" Create a fake image file for the specified git repo. """
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)
content = b"""\x00\x00\x01\x00\x01\x00\x18\x18\x00\x00\x01\x00 \x00\x88
\t\x00\x00\x16\x00\x00\x00(\x00\x00\x00\x18\x00x00\x00\x01\x00 \x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa7lM\x01\xa6kM\t\xa6kM\x01
\xa4fF\x04\xa2dE\x95\xa2cD8\xa1a
"""
parents = []
commit = None
try:
commit = repo.revparse_single('HEAD')
except KeyError:
pass
if commit:
parents = [commit.oid.hex]
# Create a file in that git repo
with open(os.path.join(newfolder, filename), 'wb') as stream:
stream.write(content)
repo.index.add(filename)
repo.index.write()
# Commits the files added
tree = repo.index.write_tree()
author = pygit2.Signature(
'Alice Author', '[email protected]')
committer = pygit2.Signature(
'Cecil Committer', '[email protected]')
repo.create_commit(
'refs/heads/master', # the name of the reference to update
author,
committer,
'Add a fake image file',
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
parents
)
# Push to origin
ori_remote = repo.remotes[0]
master_ref = repo.lookup_reference('HEAD').resolve()
refname = '%s:%s' % (master_ref.name, master_ref.name)
PagureRepo.push(ori_remote, refname)
shutil.rmtree(newfolder)
示例5: test_api_git_tags
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def test_api_git_tags(self):
""" Test the api_git_tags method of the flask api. """
tests.create_projects(self.session)
# Create a git repo to play with
gitrepo = os.path.join(tests.HERE, 'repos', 'test.git')
repo = pygit2.init_repository(gitrepo, bare=True)
newpath = tempfile.mkdtemp(prefix='pagure-fork-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', '[email protected]')
committer = pygit2.Signature(
'Cecil Committer', '[email protected]')
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:refs/heads/master'
ori_remote = clone_repo.remotes[0]
PagureRepo.push(ori_remote, refname)
# Tag our first commit
first_commit = repo.revparse_single('HEAD')
tagger = pygit2.Signature('Alice Doe', '[email protected]', 12347, 0)
repo.create_tag(
"0.0.1", first_commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger,
"Release 0.0.1")
# Check tags
output = self.app.get('/api/0/test/git/tags')
self.assertEqual(output.status_code, 200)
data = json.loads(output.data)
self.assertDictEqual(
data,
{'tags': ['0.0.1'], 'total_tags': 1}
)
shutil.rmtree(newpath)
示例6: add_commit_git_repo
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def add_commit_git_repo(
folder, ncommits=10, filename="sources", branch="master", symlink_to=None
):
""" Create some more commits for the specified git repo. """
repo, newfolder, branch_ref_obj = _clone_and_top_commits(
folder, branch, branch_ref=True
)
for index in range(ncommits):
# Create a file in that git repo
if symlink_to:
os.symlink(symlink_to, os.path.join(newfolder, filename))
else:
with open(os.path.join(newfolder, filename), "a") as stream:
stream.write("Row %s\n" % index)
repo.index.add(filename)
repo.index.write()
parents = []
commit = None
try:
if branch_ref_obj:
commit = repo[branch_ref_obj.peel().hex]
else:
commit = repo.revparse_single("HEAD")
except (KeyError, AttributeError):
pass
if commit:
parents = [commit.oid.hex]
# Commits the files added
tree = repo.index.write_tree()
author = pygit2.Signature("Alice Author", "[email protected]")
committer = pygit2.Signature("Cecil Committer", "[email protected]")
branch_ref = "refs/heads/%s" % branch
repo.create_commit(
branch_ref,
author,
committer,
"Add row %s to %s file" % (index, filename),
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
parents,
)
branch_ref_obj = pagure.lib.git.get_branch_ref(repo, branch)
# Push to origin
ori_remote = repo.remotes[0]
PagureRepo.push(ori_remote, "%s:%s" % (branch_ref, branch_ref))
shutil.rmtree(newfolder)
示例7: add_commit_git_repo
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def add_commit_git_repo(folder, ncommits=10, filename='sources'):
""" Create some more commits for the specified git repo. """
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)
for index in range(ncommits):
# Create a file in that git repo
with open(os.path.join(newfolder, filename), 'a') as stream:
stream.write('Row %s\n' % index)
repo.index.add(filename)
repo.index.write()
parents = []
commit = None
try:
commit = repo.revparse_single('HEAD')
except KeyError:
pass
if commit:
parents = [commit.oid.hex]
# Commits the files added
tree = repo.index.write_tree()
author = pygit2.Signature(
'Alice Author', '[email protected]')
committer = pygit2.Signature(
'Cecil Committer', '[email protected]')
repo.create_commit(
'refs/heads/master', # the name of the reference to update
author,
committer,
'Add row %s to %s file' % (index, filename),
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
parents,
)
# Push to origin
ori_remote = repo.remotes[0]
master_ref = repo.lookup_reference('HEAD').resolve()
refname = '%s:%s' % (master_ref.name, master_ref.name)
PagureRepo.push(ori_remote, refname)
shutil.rmtree(newfolder)
示例8: add_content_to_git
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def add_content_to_git(
folder, branch="master", filename="sources", content="foo", message=None
):
""" Create some more commits for the specified git repo. """
repo, newfolder, branch_ref_obj = _clone_and_top_commits(
folder, branch, branch_ref=True
)
# Create a file in that git repo
with open(
os.path.join(newfolder, filename), "a", encoding="utf-8"
) as stream:
stream.write("%s\n" % content)
repo.index.add(filename)
repo.index.write()
parents = []
commit = None
try:
if branch_ref_obj:
commit = repo[branch_ref_obj.peel().hex]
else:
commit = repo.revparse_single("HEAD")
except (KeyError, AttributeError):
pass
if commit:
parents = [commit.oid.hex]
# Commits the files added
tree = repo.index.write_tree()
author = pygit2.Signature("Alice Author", "[email protected]")
committer = pygit2.Signature("Cecil Committer", "[email protected]")
branch_ref = "refs/heads/%s" % branch
message = message or "Add content to file %s" % (filename)
repo.create_commit(
branch_ref, # the name of the reference to update
author,
committer,
message,
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
parents,
)
# Push to origin
ori_remote = repo.remotes[0]
PagureRepo.push(ori_remote, "%s:%s" % (branch_ref, branch_ref))
shutil.rmtree(newfolder)
示例9: _set_up_doc
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def _set_up_doc(self):
# forked doc repo
docrepo = os.path.join(self.path, "repos", "docs", "test", "test.git")
repo = pygit2.init_repository(docrepo)
# Create files in that git repo
with open(os.path.join(docrepo, "sources"), "w") as stream:
stream.write("foo\n bar")
repo.index.add("sources")
repo.index.write()
folderpart = os.path.join(docrepo, "folder1", "folder2")
os.makedirs(folderpart)
with open(os.path.join(folderpart, "test_file"), "w") as stream:
stream.write("row1\nrow2\nrow3")
repo.index.add(os.path.join("folder1", "folder2", "test_file"))
repo.index.write()
# Commits the files added
tree = repo.index.write_tree()
author = pygit2.Signature("Alice Author", "[email protected]")
committer = pygit2.Signature("Cecil Committer", "[email protected]")
repo.create_commit(
"refs/heads/master", # the name of the reference to update
author,
committer,
"Add test files and folder",
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
[],
)
# Push the changes to the bare repo
remote = repo.create_remote(
"origin", os.path.join(self.path, "repos", "docs", "test.git")
)
PagureRepo.push(remote, "refs/heads/master:refs/heads/master")
# Turn on the docs project since it's off by default
repo = pagure.lib.query.get_authorized_project(self.session, "test")
repo.settings = {"project_documentation": True}
self.session.add(repo)
self.session.commit()
示例10: add_binary_git_repo
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def add_binary_git_repo(folder, filename):
""" Create a fake image file for the specified git repo. """
repo, newfolder, parents = _clone_and_top_commits(folder, "master")
content = b"""\x00\x00\x01\x00\x01\x00\x18\x18\x00\x00\x01\x00 \x00\x88
\t\x00\x00\x16\x00\x00\x00(\x00\x00\x00\x18\x00x00\x00\x01\x00 \x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xa7lM\x01\xa6kM\t\xa6kM\x01
\xa4fF\x04\xa2dE\x95\xa2cD8\xa1a
"""
# Create a file in that git repo
with open(os.path.join(newfolder, filename), "wb") as stream:
stream.write(content)
repo.index.add(filename)
repo.index.write()
# Commits the files added
tree = repo.index.write_tree()
author = pygit2.Signature("Alice Author", "[email protected]")
committer = pygit2.Signature("Cecil Committer", "[email protected]")
repo.create_commit(
"refs/heads/master", # the name of the reference to update
author,
committer,
"Add a fake image file",
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
parents,
)
# Push to origin
ori_remote = repo.remotes[0]
master_ref = repo.lookup_reference("HEAD").resolve()
refname = "%s:%s" % (master_ref.name, master_ref.name)
PagureRepo.push(ori_remote, refname)
shutil.rmtree(newfolder)
示例11: add_tag_git_repo
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def add_tag_git_repo(folder, tagname, obj_hash, message):
""" Add a tag to the given object of the given repo annotated by given message. """
repo, newfolder, branch_ref_obj = _clone_and_top_commits(
folder, "master", branch_ref=True
)
tag_sha = repo.create_tag(
tagname,
obj_hash,
repo.get(obj_hash).type,
pygit2.Signature("Alice Author", "[email protected]"),
message,
)
# Push to origin
ori_remote = repo.remotes[0]
PagureRepo.push(
ori_remote, "refs/tags/%s:refs/tags/%s" % (tagname, tagname)
)
shutil.rmtree(newfolder)
return tag_sha
示例12: set_up_git_repo
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [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', '[email protected]')
committer = pygit2.Signature(
'Cecil Committer', '[email protected]')
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)
示例13: add_readme_git_repo
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def add_readme_git_repo(folder):
""" Create a README file for the specified git repo. """
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)
content = """Pagure
======
:Author: Pierre-Yves Chibon <[email protected]>
Pagure is a light-weight git-centered forge based on pygit2.
Currently, Pagure offers a web-interface for git repositories, a ticket
system and possibilities to create new projects, fork existing ones and
create/merge pull-requests across or within projects.
Homepage: https://github.com/pypingou/pagure
Dev instance: http://209.132.184.222/ (/!\\ May change unexpectedly, it's a dev instance ;-))
"""
parents = []
commit = None
try:
commit = repo.revparse_single('HEAD')
except KeyError:
pass
if commit:
parents = [commit.oid.hex]
# Create a file in that git repo
with open(os.path.join(newfolder, 'README.rst'), 'w') as stream:
stream.write(content)
repo.index.add('README.rst')
repo.index.write()
# Commits the files added
tree = repo.index.write_tree()
author = pygit2.Signature(
'Alice Author', '[email protected]')
committer = pygit2.Signature(
'Cecil Committer', '[email protected]')
repo.create_commit(
'refs/heads/master', # the name of the reference to update
author,
committer,
'Add a README file',
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
parents
)
# Push to origin
ori_remote = repo.remotes[0]
master_ref = repo.lookup_reference('HEAD').resolve()
refname = '%s:%s' % (master_ref.name, master_ref.name)
PagureRepo.push(ori_remote, refname)
shutil.rmtree(newfolder)
示例14: test_view_docs
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def test_view_docs(self):
""" Test the view_docs endpoint. """
tests.create_projects(self.session)
repo = pygit2.init_repository(
os.path.join(tests.HERE, 'docs', 'test.git'), bare=True)
output = self.app.get('/test/docs')
self.assertEqual(output.status_code, 404)
# forked doc repo
docrepo = os.path.join(tests.HERE, 'docs', 'test', 'test.git')
repo = pygit2.init_repository(docrepo)
# Create files in that git repo
with open(os.path.join(docrepo, 'sources'), 'w') as stream:
stream.write('foo\n bar')
repo.index.add('sources')
repo.index.write()
folderpart = os.path.join(docrepo, 'folder1', 'folder2')
os.makedirs(folderpart)
with open(os.path.join(folderpart, 'test_file'), 'w') as stream:
stream.write('row1\nrow2\nrow3')
repo.index.add(os.path.join('folder1', 'folder2', 'test_file'))
repo.index.write()
# Commits the files added
tree = repo.index.write_tree()
author = pygit2.Signature(
'Alice Author', '[email protected]')
committer = pygit2.Signature(
'Cecil Committer', '[email protected]')
repo.create_commit(
'refs/heads/master', # the name of the reference to update
author,
committer,
'Add test files and folder',
# binary string representing the tree object ID
tree,
# list of binary strings representing parents of the new commit
[]
)
# Push the changes to the bare repo
remote = repo.create_remote(
'origin', os.path.join(tests.HERE, 'docs', 'test.git'))
PagureRepo.push(remote, 'refs/heads/master:refs/heads/master')
# Now check the UI
output = self.app.get('/test/docs')
self.assertEqual(output.status_code, 404)
output = self.app.get('/test/sources')
self.assertEqual(output.status_code, 200)
self.assertEqual('<pre>foo\n bar</pre>', output.data)
output = self.app.get('/test/folder1/folder2')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li><ul><a href="test_file">test_file</a></ul></li>'
in output.data)
output = self.app.get('/test/folder1/folder2/test_file')
self.assertEqual(output.status_code, 200)
self.assertEqual('<pre>row1\nrow2\nrow3</pre>', output.data)
output = self.app.get('/test/folder1')
self.assertEqual(output.status_code, 200)
self.assertTrue(
'<li><ul><a href="folder2">folder2/</a></ul></li>'
in output.data)
output = self.app.get('/test/folder1/foo')
self.assertEqual(output.status_code, 404)
output = self.app.get('/test/folder1/foo/folder2')
self.assertEqual(output.status_code, 404)
示例15: add_file_to_git
# 需要导入模块: from pagure.lib.repo import PagureRepo [as 别名]
# 或者: from pagure.lib.repo.PagureRepo import push [as 别名]
def add_file_to_git(repo, issue, ticketfolder, user, filename, filestream):
''' Add a given file to the specified ticket git repository.
:arg repo: the Project object from the database
:arg ticketfolder: the folder on the filesystem where the git repo for
tickets are stored
:arg user: the user object with its username and email
:arg filename: the name of the file to save
:arg filestream: the actual content of the file
'''
if not ticketfolder:
return
# Prefix the filename with a timestamp:
filename = '%s-%s' % (
hashlib.sha256(filestream.read()).hexdigest(),
werkzeug.secure_filename(filename)
)
# Get the fork
repopath = os.path.join(ticketfolder, repo.path)
# Clone the repo into a temp folder
newpath = tempfile.mkdtemp(prefix='pagure-')
new_repo = pygit2.clone_repository(repopath, newpath)
folder_path = os.path.join(newpath, 'files')
file_path = os.path.join(folder_path, filename)
# Get the current index
index = new_repo.index
# Are we adding files
added = False
if not os.path.exists(file_path):
added = True
else:
# File exists, remove the clone and return
shutil.rmtree(newpath)
return os.path.join('files', filename)
if not os.path.exists(folder_path):
os.mkdir(folder_path)
# Write down what changed
filestream.seek(0)
with open(file_path, 'w') as stream:
stream.write(filestream.read())
# Retrieve the list of files that changed
diff = new_repo.diff()
files = [patch.new_file_path for patch in diff]
# Add the changes to the index
if added:
index.add(os.path.join('files', filename))
for filename in files:
index.add(filename)
# If not change, return
if not files and not added:
shutil.rmtree(newpath)
return
# See if there is a parent to this commit
parent = None
try:
parent = new_repo.head.get_object().oid
except pygit2.GitError:
pass
parents = []
if parent:
parents.append(parent)
# Author/commiter will always be this one
author = pygit2.Signature(
name=user.username.encode('utf-8'),
email=user.email.encode('utf-8')
)
# Actually commit
new_repo.create_commit(
'refs/heads/master',
author,
author,
'Add file %s to ticket %s: %s' % (filename, issue.uid, issue.title),
new_repo.index.write_tree(),
parents)
index.write()
# Push to origin
ori_remote = new_repo.remotes[0]
master_ref = new_repo.lookup_reference('HEAD').resolve()
refname = '%s:%s' % (master_ref.name, master_ref.name)
PagureRepo.push(ori_remote, refname)
#.........这里部分代码省略.........