General

Top level constants and exceptions from the library.

Version

The following constants provide information about the version of the libgit2 library that has been built against. The version number has a MAJOR.MINOR.REVISION format.

LIBGIT2_VER_MAJOR

Integer value of the major version number. For example, for the version 1.9.7:

>>> print(pygit2.LIBGIT2_VER_MAJOR)
1
LIBGIT2_VER_MINOR

Integer value of the minor version number. For example, for the version 1.9.7:

>>> print(pygit2.LIBGIT2_VER_MINOR)
9
LIBGIT2_VER_REVISION

Integer value of the revision version number. For example, for the version 1.9.7:

>>> print(pygit2.LIBGIT2_VER_REVISION)
6
LIBGIT2_VER

Tuple value of the revision version numbers. For example, for the version 1.9.7:

>>> print(pygit2.LIBGIT2_VER)
(1, 9, 6)
LIBGIT2_VERSION

The libgit2 version number as a string:

>>> print(pygit2.LIBGIT2_VERSION)
'1.9.7'

Options

pygit2.option(option_type: Literal[Option.GET_MWINDOW_SIZE, Option.GET_MWINDOW_MAPPED_LIMIT, Option.GET_MWINDOW_FILE_LIMIT]) int
pygit2.option(option_type: Literal[Option.SET_MWINDOW_SIZE, Option.SET_MWINDOW_MAPPED_LIMIT, Option.SET_MWINDOW_FILE_LIMIT, Option.SET_CACHE_MAX_SIZE], arg1: int) None
pygit2.option(option_type: Literal[Option.GET_SEARCH_PATH], arg1: ConfigLevel) str
pygit2.option(option_type: Literal[Option.SET_SEARCH_PATH], arg1: ConfigLevel, arg2: str) None
pygit2.option(option_type: Literal[Option.SET_CACHE_OBJECT_LIMIT], arg1: ObjectType, arg2: int) None
pygit2.option(option_type: Literal[Option.GET_CACHED_MEMORY]) tuple[int, int]
pygit2.option(option_type: Literal[Option.SET_SSL_CERT_LOCATIONS], arg1: str | bytes | None, arg2: str | bytes | None) None
pygit2.option(option_type: Literal[Option.ENABLE_CACHING, Option.ENABLE_STRICT_OBJECT_CREATION, Option.ENABLE_STRICT_SYMBOLIC_REF_CREATION, Option.ENABLE_OFS_DELTA, Option.ENABLE_FSYNC_GITDIR, Option.ENABLE_STRICT_HASH_VERIFICATION, Option.ENABLE_UNSAVED_INDEX_SAFETY, Option.DISABLE_PACK_KEEP_FILE_CHECKS, Option.SET_OWNER_VALIDATION], arg1: bool) None
pygit2.option(option_type: Literal[Option.GET_OWNER_VALIDATION]) bool
pygit2.option(option_type: Literal[Option.GET_TEMPLATE_PATH, Option.GET_USER_AGENT, Option.GET_HOMEDIR, Option.GET_USER_AGENT_PRODUCT]) str | None
pygit2.option(option_type: Literal[Option.SET_TEMPLATE_PATH, Option.SET_USER_AGENT, Option.SET_SSL_CIPHERS, Option.SET_HOMEDIR, Option.SET_USER_AGENT_PRODUCT], arg1: str | bytes) None
pygit2.option(option_type: Literal[Option.GET_WINDOWS_SHAREMODE, Option.GET_PACK_MAX_OBJECTS, Option.GET_SERVER_CONNECT_TIMEOUT, Option.GET_SERVER_TIMEOUT]) int
pygit2.option(option_type: Literal[Option.SET_WINDOWS_SHAREMODE, Option.SET_PACK_MAX_OBJECTS, Option.ENABLE_HTTP_EXPECT_CONTINUE, Option.SET_ODB_PACKED_PRIORITY, Option.SET_ODB_LOOSE_PRIORITY, Option.SET_SERVER_CONNECT_TIMEOUT, Option.SET_SERVER_TIMEOUT], arg1: int) None
pygit2.option(option_type: Literal[Option.GET_EXTENSIONS]) list[str]
pygit2.option(option_type: Literal[Option.SET_EXTENSIONS], arg1: list[str], arg2: int) None
pygit2.option(option_type: Literal[Option.ADD_SSL_X509_CERT], arg1: str | bytes) None
pygit2.option(option_type: Option, arg1: Any = <object object>, arg2: Any = <object object>) Any

Get or set a libgit2 option.

Parameters:

GIT_OPT_GET_SEARCH_PATH, level

Get the config search path for the given level.

GIT_OPT_SET_SEARCH_PATH, level, path

Set the config search path for the given level.

GIT_OPT_GET_MWINDOW_SIZE

Get the maximum mmap window size.

GIT_OPT_SET_MWINDOW_SIZE, size

Set the maximum mmap window size.

GIT_OPT_GET_MWINDOW_FILE_LIMIT

Get the maximum number of files that will be mapped at any time by the library.

GIT_OPT_SET_MWINDOW_FILE_LIMIT, size

Set the maximum number of files that can be mapped at any time by the library. The default (0) is unlimited.

GIT_OPT_GET_OWNER_VALIDATION

Gets the owner validation setting for repository directories.

GIT_OPT_SET_OWNER_VALIDATION, enabled

Set that repository directories should be owned by the current user. The default is to validate ownership.

GIT_OPT_GET_TEMPLATE_PATH

Get the default template path.

GIT_OPT_SET_TEMPLATE_PATH, path

Set the default template path.

GIT_OPT_GET_USER_AGENT

Get the user agent string.

GIT_OPT_SET_USER_AGENT, user_agent

Set the user agent string.

GIT_OPT_GET_PACK_MAX_OBJECTS

Get the maximum number of objects to include in a pack.

GIT_OPT_SET_PACK_MAX_OBJECTS, count

Set the maximum number of objects to include in a pack.

Exceptions

exception pygit2.GitError

Bases: Exception

Generic libgit2 error.

exception pygit2.AlreadyExistsError

Bases: GitError, ValueError

Object already exists.

Exception when trying to create an object (reference, etc) that already exists.

exception pygit2.InvalidSpecError

Bases: GitError, ValueError

Invalid name/ref spec.

Exception when an input specification such as a reference name is invalid.

exception pygit2.InvalidError

Bases: GitError, ValueError

Invalid operation or input.

Exception when an operation or input is invalid.

exception pygit2.NotFoundError

Bases: GitError, KeyError

Requested object could not be found.

Exception when a requested object could not be found.

exception pygit2.AmbiguousError

Bases: GitError, ValueError

More than one object matches.

Exception when more than one object matches.

exception pygit2.AuthError

Bases: GitError

Authentication error.

Exception when an authentication error occurs.

exception pygit2.CertificateError

Bases: GitError

Server certificate is invalid.

Exception when a server certificate is invalid.

exception pygit2.Passthrough

Bases: Exception

Exception that can be raised from a callback to tell libgit2 to behave as if that callback had not been set. See Callbacks for details.

Error mapping

The following table shows how libgit2 error codes map to pygit2 exceptions. The new exception classes inherit from pygit2.GitError and, where noted, from a Python built-in exception for backward compatibility.

pygit2 exception

libgit2 code / class

Built-in base

AlreadyExistsError

GIT_EEXISTS

ValueError

InvalidSpecError

GIT_EINVALIDSPEC

ValueError

InvalidError

GIT_EINVALID, GIT_ERROR_INVALID

ValueError

NotFoundError

GIT_ENOTFOUND

KeyError

AmbiguousError

GIT_EAMBIGUOUS

ValueError

AuthError

GIT_EAUTH

CertificateError

GIT_ECERTIFICATE

GitError

generic / other errors