簡體   English   中英

AttributeError: '_pygit2.Reference' object 沒有屬性 'get_object'

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

我正在嘗試自動執行在我的遙控器中創建和克隆存儲庫的任務,當我運行以下代碼時,似乎我嘗試使用的方法可能已被棄用。 什么是替代方法?


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

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'

我最近遇到了同樣的問題,在調試時我發現你需要將 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