Index file.
Index read:
>>> index = repo.index
>>> index.read()
>>> oid = index['path/to/file'].oid # 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
Add or update an index entry from a file in disk.
Removes an entry from index.
Clear the contents (all the entries) of an index object.
Update the contents of an existing index object in memory by reading from the hard disk.Arguments:
force: if True (the default) allways reload. If False, only if the file has changed
Write an existing index object from memory back to disk using an atomic file lock.
Update the index file from the tree identified by the given oid.
Create a tree object from the index file, return its oid.
Return a Diff object with the differences between the index and the given tree.
Arguments:
tree: the tree to diff.
flag: a GIT_DIFF_* constant.
Return a Diff object with the differences between the index and the working copy.
Arguments:
flag: a GIT_DIFF_* constant.
Reads the status of the repository and returns a dictionary with file paths as keys and status flags as values. See pygit2.GIT_STATUS_*.
Returns the status of the given file path.
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 the given reference using the given strategy, and update the HEAD. The reference may be a reference name or a Reference object. The default strategy is GIT_CHECKOUT_SAFE_CREATE.
To checkout from the HEAD, just pass ‘HEAD’:
>>> checkout('HEAD')
If no reference is given, checkout from the index.
Lower level API:
Checkout the head using the given strategy.
Checkout the given tree, commit or tag, using the given strategy.
Checkout the index using the given strategy.