0

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

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'
ScottyBlades
  • 12,189
  • 5
  • 77
  • 85

1 Answers1

0

I recently faced the same issue, and upon debugging i found this where you need to update oid to this

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

sids1991
  • 11
  • 1