0

我正在尝试自动执行在我的遥控器中创建和克隆存储库的任务,当我运行以下代码时,似乎我尝试使用的方法可能已被弃用。什么是替代方法?


from github import Github
import pygit2

name = input("Name of iOS project: ") # repo name
description = input("github description: ") # description
# using username and password establish connection to github
g = Github(username, password)
gituser = g.get_user()
repo = gituser.create_repo(name) # 

#create some new files in the repo
repo.create_file("README.md", "init commit", "my description")

#Clone the newly created repo
repoClone = pygit2.clone_repository(repo.git_url, 'https://github.com/scott-lydon/'+name+'.git')

#put the files in the repository here

#Commit it
repoClone.remotes.set_url("origin", repo.clone_url)
index = repoClone.index
index.add_all()
index.write()
author = pygit2.Signature("your name", "your email")
commiter = pygit2.Signature("your name", "your email")
tree = index.write_tree()
oid = repoClone.create_commit('refs/heads/master', author, commiter, "init commit",tree,[repoClone.head.get_object().hex])
remote = repoClone.remotes["origin"]
credentials = pygit2.UserPass(username, password)
remote.credentials = credentials

callbacks=pygit2.RemoteCallbacks(credentials=credentials)

remote.push(['refs/heads/master'],callbacks=callbacks)

输出

Traceback (most recent call last):

  File "/Users/---/Python/generateiOSProj/untitled3.py", line 39, in <module>
    oid = repoClone.create_commit('refs/heads/master', author, commiter, "init commit",tree,[repoClone.head.get_object().hex])

AttributeError: '_pygit2.Reference' object has no attribute 'get_object'
4

1 回答 1

0

我最近遇到了同样的问题,在调试时我发现你需要将 oid 更新为此

oid = repoClone.create_commit('refs/heads/master', author, commiter, "init commit",tree,[repoClone.head.target])

于 2020-09-10T21:53:40.167 回答