Carlos Martín Nieto 31fc235b59 Fix sphinx complaints about the docs
Use the right namespace so Refspec and TransferProgress show up. These
classes are not instantiated by the user, so they were not promoted to
the pygit2 module. Use autoclass so it lists everything for us.

Also use autoclass for the reflog. We had a difference is oid vs id
between the docs and the code.
2014-07-10 08:25:54 +02:00

3.7 KiB

References

pygit2.Repository.listall_references

pygit2.Repository.lookup_reference

Example:

>>> all_refs = repo.listall_references()
>>> master_ref = repo.lookup_reference("refs/heads/master")
>>> commit = master_ref.get_object() # or repo[master_ref.target]

The Reference type

pygit2.Reference.name

pygit2.Reference.shorthand

pygit2.Reference.target

pygit2.Reference.type

pygit2.Reference.delete

pygit2.Reference.rename

pygit2.Reference.resolve

pygit2.Reference.log

pygit2.Reference.log_append

Example:

>>> branch = repository.lookup_reference("refs/heads/master")
>>> branch.target = another_commit.id
>>> committer = Signature('Cecil Committer', 'cecil@committers.tld')
>>> branch.log_append(another_commit.id, committer,
                      "changed branch target using pygit2")

This creates a reflog entry in git reflog master which looks like:

7296b92 master@{10}: changed branch target using pygit2

In order to make an entry in git reflog, ie. the reflog for HEAD, you have to get the Reference object for HEAD and call log_append on that.

pygit2.Reference.get_object

The HEAD

Example. These two lines are equivalent:

>>> head = repo.lookup_reference('HEAD').resolve()
>>> head = repo.head

pygit2.Repository.head

pygit2.Repository.head_is_detached

pygit2.Repository.head_is_unborn

Branches

Branches inherit from References, and additionally provide specialized accessors for some unique features.

pygit2.Repository.listall_branches

pygit2.Repository.lookup_branch

pygit2.Repository.create_branch

Example:

>>> local_branches = repo.listall_branches()
>>> # equivalent to
>>> local_branches = repo.listall_branches(pygit2.GIT_BRANCH_LOCAL)

>>> remote_branches = repo.listall_branches(pygit2.GIT_BRANCH_REMOTE)

>>> all_branches = repo.listall_branches(pygit2.GIT_BRANCH_REMOTE |
                                         pygit2.GIT_BRANCH_LOCAL)

>>> master_branch = repo.lookup_branch('master')
>>> # equivalent to
>>> master_branch = repo.lookup_branch('master',
                                       pygit2.GIT_BRANCH_LOCAL)

>>> remote_branch = repo.lookup_branch('upstream/feature',
                                       pygit2.GIT_BRANCH_REMOTE)

The Branch type

pygit2.Branch.branch_name

pygit2.Branch.remote_name

pygit2.Branch.upstream

pygit2.Branch.upstream_name

pygit2.Branch.rename

pygit2.Branch.delete

pygit2.Branch.is_head

The reference log

Example:

>>> head = repo.lookup_reference('refs/heads/master')
>>> for entry in head.log():
...     print(entry.message)

pygit2.RefLogEntry

Notes

pygit2.Repository.notes

pygit2.Repository.create_note

pygit2.Repository.lookup_note

The Note type

pygit2.Note.annotated_id

pygit2.Note.id

pygit2.Note.message

pygit2.Note.remove