简体   繁体   English

AttributeError: '_pygit2.Reference' object 没有属性 'get_object'

[英]AttributeError: '_pygit2.Reference' object has no attribute 'get_object'

I'm trying to automate the task of creating and cloning a repository in my remote, when I run the following code, it seems that the method I'm trying to use may have been deprecated.我正在尝试自动执行在我的遥控器中创建和克隆存储库的任务,当我运行以下代码时,似乎我尝试使用的方法可能已被弃用。 What is the alternative method?什么是替代方法?


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)

Output Output

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'

I recently faced the same issue, and upon debugging i found this where you need to update oid to this我最近遇到了同样的问题,在调试时我发现你需要将 oid 更新为此

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM