pygit2 / libgit2 AttributeError: '_pygit2.Reference' object has no attribute 'oid'
Question: I am trying to create a repository and commit a file to it, but getting the
error AttributeError: '_pygit2.Reference' object has no attribute 'oid'

Any advice welcomed.

    
    
    (venv3.4.1) ubuntu@app:/var/www/app-/src/tests/api$ python test_git_repo.py 
    Traceback (most recent call last):
      File "test_git_repo.py", line 35, in <module>
        add_file_to_repo()
      File "test_git_repo.py", line 31, in add_file_to_repo
        repo.create_commit('HEAD',author, committer,'Files saved by front end commit.', treeid, [repo.head.oid] )
    AttributeError: '_pygit2.Reference' object has no attribute 'oid'
    (venv3.4.1) ubuntu@app:/var/www/app-/src/tests/api$ cat test
    cat: test: No such file or directory
    (venv3.4.1) ubuntu@app:/var/www/app-/src/tests/api$ cat test_git_repo.py 
    import pygit2
    from time import time
    import io
    import sys
    
    repo_id = 'my_repo01'
    repo_location = '/usr/local/repo/' + repo_id
    author = pygit2.Signature('Author Name', 'author@example.org', int(time()), 0)
    committer = author
    
    def create_repo():
        repo = pygit2.init_repository(repo_location, bare=True) # Creates a bare repository
        bld = repo.TreeBuilder()
        t = bld.write()
        c = repo.create_commit('HEAD', author, committer, 'Create master branch', t, [])
    
    def add_file_to_repo():
        repo = pygit2.Repository(repo_location)
        head = repo.head
        f = io.BytesIO()
        f.write(b'hello')
        # create the file as blob in git
        blob_id = repo.write(pygit2.GIT_OBJ_BLOB, f.read()) 
        # add file to index/working area
        index = repo.index
        index.read()
        new_entry = pygit2.IndexEntry('path/to/my/file.txt', blob_id, pygit2.GIT_FILEMODE_BLOB)
        index.add(new_entry)
        treeid = index.write_tree()
        index.write() # write index to disk
        repo.create_commit('HEAD',author, committer,'Files saved by front end commit.', treeid, [repo.head.oid] )
        f.close()
    
    create_repo()
    add_file_to_repo()
    
    (venv3.4.1) ubuntu@app:/var/www/app-/src/tests/api$ 
    


Answer: As you can see from the docs for references at [0], the object or reference
they point to is accessed through the `target` field.

[0] <http://www.pygit2.org/references.html#the-reference-type>

