The Index file and the Working copy

Index read:

>>> index = repo.index
>>> index.read()
>>> oid = index['path/to/file'].id    # from path to object id
>>> blob = repo[oid]                   # from object id to object

Iterate over all entries of the index:

>>> for entry in index:
...     print entry.path, entry.hex

Index write:

>>> index.add('path/to/file')          # git add
>>> del index['path/to/file']          # git rm
>>> index.write()                      # don't forget to save the changes
Custom entries::
>>> entry = pygit2.IndexEntry('README.md', blob_id, blob_filemode)
>>> repo.index.add(entry)

The Index type

The IndexEntry type

Status

Inspect the status of the repository:

>>> from pygit2 import GIT_STATUS_CURRENT
>>> status = repo.status()
>>> for filepath, flags in status.items():
...     if flags != GIT_STATUS_CURRENT:
...         print "Filepath %s isn't clean" % filepath

Checkout

Lower level API:

Table Of Contents

Previous topic

Commit log

Next topic

Diff

This Page