deb-python-pygit2/docs/working-copy.rst
J. David Ibáñez 974f16ca69 Re-work the checkout API
New API:

  Repository.head = refname
  Repository.checkout_head(strategy)
  Repository.checkout_index(strategy)
  Repository.checkout_tree(treeish, strategy)

Changed API:

  # Before
  Repository.checkout(strategy=GIT_CHECKOUT_SAFE_CREATE, reference=None,
                      head=False)

  # Now
  Repository.checkout(refname=None, strategy=GIT_CHECKOUT_SAFE_CREATE)
2013-05-05 21:45:39 +02:00

1.8 KiB

The Index file and the Working copy

pygit2.Repository.index

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

The Index type

pygit2.Index.add

pygit2.Index.remove

pygit2.Index.clear

pygit2.Index.read

pygit2.Index.write

pygit2.Index.read_tree

pygit2.Index.write_tree

pygit2.Index.diff

The IndexEntry type

pygit2.IndexEntry.oid

pygit2.IndexEntry.hex

pygit2.IndexEntry.path

pygit2.IndexEntry.mode

Status

pygit2.Repository.status

pygit2.Repository.status_file

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

pygit2.Repository.checkout

Lower level API:

pygit2.Repository.checkout_head

pygit2.Repository.checkout_tree

pygit2.Repository.checkout_index