Add stubs for pygit2 (#11374)

The upstream library is very tricky to type (likely requires nontrivial
refactoring), and only contains partial type information, but stubs are
a lot easier because only the public signatures are involved this way,
so I plan to first make the library usable in typed projects by making
stubs available here, then gradually work my way upstream.

The stubs are auto-generated then completed with fully manual inspection
of every Python source file. The `_pygit2.pyi` comes from upstream and
is mostly untouched except for required style changes, the signature of
`options()`, and `FilterSource` which is missing from upstream.
This commit is contained in:
WÁNG Xuěruì
2024-03-12 13:48:12 +08:00
committed by GitHub
parent dea4dd1dc1
commit 9a4b605065
28 changed files with 2118 additions and 0 deletions

View File

@@ -62,6 +62,7 @@
"stubs/psycopg2",
"stubs/pyasn1",
"stubs/pyflakes",
"stubs/pygit2",
"stubs/Pygments",
"stubs/PyMySQL",
"stubs/python-dateutil",

View File

@@ -0,0 +1,17 @@
# stubtest wrongly checks the Python implementation with the cffi type's
# stubs, likely due to name shadowing that happens at import-time
pygit2.Repository.__init__
pygit2.Repository._from_c
# @cached_property that fail to get recognized as such by stubtest
pygit2.config.ConfigEntry.level
pygit2.config.ConfigEntry.raw_name
pygit2.config.ConfigEntry.raw_value
# Actual signatures enforced by C-level checks not visible to stubtest
pygit2.Mailmap.__init__
pygit2.OdbBackend.__init__
pygit2.RefLogEntry.__init__
pygit2.RefdbBackend.__init__
pygit2._pygit2.Mailmap.__init__
pygit2._pygit2.OdbBackend.__init__
pygit2._pygit2.RefLogEntry.__init__
pygit2._pygit2.RefdbBackend.__init__

View File

@@ -0,0 +1,6 @@
version = "1.14.*"
upstream_repository = "https://github.com/libgit2/pygit2"
requires = ["types-cffi"]
[tool.stubtest]
platforms = ["darwin", "linux", "win32"]

View File

@@ -0,0 +1,54 @@
from _typeshed import StrOrBytesPath, SupportsAllComparisons
from collections.abc import Callable
from . import enums
from ._build import __version__ as __version__
from ._pygit2 import *
from .blame import Blame as Blame, BlameHunk as BlameHunk
from .blob import BlobIO as BlobIO
from .callbacks import (
CheckoutCallbacks as CheckoutCallbacks,
Payload as Payload,
RemoteCallbacks,
StashApplyCallbacks as StashApplyCallbacks,
get_credentials as get_credentials,
)
from .config import Config as Config
from .credentials import *
from .errors import Passthrough as Passthrough
from .filter import Filter as Filter
from .index import Index as Index, IndexEntry as IndexEntry
from .legacyenums import *
from .packbuilder import PackBuilder as PackBuilder
from .remotes import Remote as Remote
from .repository import Repository # type: ignore[assignment]
from .settings import Settings
from .submodules import Submodule as Submodule
features: enums.Feature
LIBGIT2_VER: tuple[int, int, int]
def init_repository(
path: StrOrBytesPath | None,
bare: bool = False,
flags: enums.RepositoryInitFlag = ...,
mode: int | enums.RepositoryInitMode = ...,
workdir_path: str | None = None,
description: str | None = None,
template_path: str | None = None,
initial_head: str | None = None,
origin_url: str | None = None,
) -> Repository: ...
def clone_repository(
url: str,
path: str,
bare: bool = False,
repository: Callable[[str, bool], Repository] | None = None,
remote: Callable[[Repository, str, str], Remote] | None = None,
checkout_branch: str | None = None,
callbacks: RemoteCallbacks | None = None,
depth: int = 0,
) -> Repository: ...
tree_entry_key: Callable[[Object], SupportsAllComparisons] # functools.cmp_to_key(tree_entry_cmp)
settings: Settings

View File

@@ -0,0 +1,5 @@
from pathlib import Path
__version__: str
def get_libgit2_paths() -> tuple[Path, dict[str, list[str]]]: ...

View File

@@ -0,0 +1,4 @@
from _cffi_backend import FFI, Lib
ffi: FFI
lib: Lib

View File

@@ -0,0 +1,777 @@
from _typeshed import StrOrBytesPath
from collections.abc import Iterator
from io import IOBase
from typing import Any, Literal, final, overload
from typing_extensions import TypeAlias
from . import Index
from .enums import (
ApplyLocation,
BranchType,
DiffFind,
DiffFlag,
DiffOption,
DiffStatsFormat,
FileMode,
FileStatus,
MergeAnalysis,
MergePreference,
ObjectType,
Option,
ReferenceFilter,
ReferenceType,
ResetMode,
SortMode,
)
from .filter import Filter
GIT_APPLY_LOCATION_BOTH: int
GIT_APPLY_LOCATION_INDEX: int
GIT_APPLY_LOCATION_WORKDIR: int
GIT_BLAME_FIRST_PARENT: int
GIT_BLAME_IGNORE_WHITESPACE: int
GIT_BLAME_NORMAL: int
GIT_BLAME_TRACK_COPIES_ANY_COMMIT_COPIES: int
GIT_BLAME_TRACK_COPIES_SAME_COMMIT_COPIES: int
GIT_BLAME_TRACK_COPIES_SAME_COMMIT_MOVES: int
GIT_BLAME_TRACK_COPIES_SAME_FILE: int
GIT_BLAME_USE_MAILMAP: int
GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT: int
GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD: int
GIT_BLOB_FILTER_CHECK_FOR_BINARY: int
GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES: int
GIT_BRANCH_ALL: int
GIT_BRANCH_LOCAL: int
GIT_BRANCH_REMOTE: int
GIT_CHECKOUT_ALLOW_CONFLICTS: int
GIT_CHECKOUT_CONFLICT_STYLE_DIFF3: int
GIT_CHECKOUT_CONFLICT_STYLE_MERGE: int
GIT_CHECKOUT_CONFLICT_STYLE_ZDIFF3: int
GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH: int
GIT_CHECKOUT_DONT_OVERWRITE_IGNORED: int
GIT_CHECKOUT_DONT_REMOVE_EXISTING: int
GIT_CHECKOUT_DONT_UPDATE_INDEX: int
GIT_CHECKOUT_DONT_WRITE_INDEX: int
GIT_CHECKOUT_DRY_RUN: int
GIT_CHECKOUT_FORCE: int
GIT_CHECKOUT_NONE: int
GIT_CHECKOUT_NO_REFRESH: int
GIT_CHECKOUT_RECREATE_MISSING: int
GIT_CHECKOUT_REMOVE_IGNORED: int
GIT_CHECKOUT_REMOVE_UNTRACKED: int
GIT_CHECKOUT_SAFE: int
GIT_CHECKOUT_SKIP_LOCKED_DIRECTORIES: int
GIT_CHECKOUT_SKIP_UNMERGED: int
GIT_CHECKOUT_UPDATE_ONLY: int
GIT_CHECKOUT_USE_OURS: int
GIT_CHECKOUT_USE_THEIRS: int
GIT_CONFIG_HIGHEST_LEVEL: int
GIT_CONFIG_LEVEL_APP: int
GIT_CONFIG_LEVEL_GLOBAL: int
GIT_CONFIG_LEVEL_LOCAL: int
GIT_CONFIG_LEVEL_PROGRAMDATA: int
GIT_CONFIG_LEVEL_SYSTEM: int
GIT_CONFIG_LEVEL_XDG: int
GIT_DELTA_ADDED: int
GIT_DELTA_CONFLICTED: int
GIT_DELTA_COPIED: int
GIT_DELTA_DELETED: int
GIT_DELTA_IGNORED: int
GIT_DELTA_MODIFIED: int
GIT_DELTA_RENAMED: int
GIT_DELTA_TYPECHANGE: int
GIT_DELTA_UNMODIFIED: int
GIT_DELTA_UNREADABLE: int
GIT_DELTA_UNTRACKED: int
GIT_DESCRIBE_ALL: int
GIT_DESCRIBE_DEFAULT: int
GIT_DESCRIBE_TAGS: int
GIT_DIFF_BREAK_REWRITES: int
GIT_DIFF_BREAK_REWRITES_FOR_RENAMES_ONLY: int
GIT_DIFF_DISABLE_PATHSPEC_MATCH: int
GIT_DIFF_ENABLE_FAST_UNTRACKED_DIRS: int
GIT_DIFF_FIND_ALL: int
GIT_DIFF_FIND_AND_BREAK_REWRITES: int
GIT_DIFF_FIND_BY_CONFIG: int
GIT_DIFF_FIND_COPIES: int
GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED: int
GIT_DIFF_FIND_DONT_IGNORE_WHITESPACE: int
GIT_DIFF_FIND_EXACT_MATCH_ONLY: int
GIT_DIFF_FIND_FOR_UNTRACKED: int
GIT_DIFF_FIND_IGNORE_LEADING_WHITESPACE: int
GIT_DIFF_FIND_IGNORE_WHITESPACE: int
GIT_DIFF_FIND_REMOVE_UNMODIFIED: int
GIT_DIFF_FIND_RENAMES: int
GIT_DIFF_FIND_RENAMES_FROM_REWRITES: int
GIT_DIFF_FIND_REWRITES: int
GIT_DIFF_FLAG_BINARY: int
GIT_DIFF_FLAG_EXISTS: int
GIT_DIFF_FLAG_NOT_BINARY: int
GIT_DIFF_FLAG_VALID_ID: int
GIT_DIFF_FLAG_VALID_SIZE: int
GIT_DIFF_FORCE_BINARY: int
GIT_DIFF_FORCE_TEXT: int
GIT_DIFF_IGNORE_BLANK_LINES: int
GIT_DIFF_IGNORE_CASE: int
GIT_DIFF_IGNORE_FILEMODE: int
GIT_DIFF_IGNORE_SUBMODULES: int
GIT_DIFF_IGNORE_WHITESPACE: int
GIT_DIFF_IGNORE_WHITESPACE_CHANGE: int
GIT_DIFF_IGNORE_WHITESPACE_EOL: int
GIT_DIFF_INCLUDE_CASECHANGE: int
GIT_DIFF_INCLUDE_IGNORED: int
GIT_DIFF_INCLUDE_TYPECHANGE: int
GIT_DIFF_INCLUDE_TYPECHANGE_TREES: int
GIT_DIFF_INCLUDE_UNMODIFIED: int
GIT_DIFF_INCLUDE_UNREADABLE: int
GIT_DIFF_INCLUDE_UNREADABLE_AS_UNTRACKED: int
GIT_DIFF_INCLUDE_UNTRACKED: int
GIT_DIFF_INDENT_HEURISTIC: int
GIT_DIFF_MINIMAL: int
GIT_DIFF_NORMAL: int
GIT_DIFF_PATIENCE: int
GIT_DIFF_RECURSE_IGNORED_DIRS: int
GIT_DIFF_RECURSE_UNTRACKED_DIRS: int
GIT_DIFF_REVERSE: int
GIT_DIFF_SHOW_BINARY: int
GIT_DIFF_SHOW_UNMODIFIED: int
GIT_DIFF_SHOW_UNTRACKED_CONTENT: int
GIT_DIFF_SKIP_BINARY_CHECK: int
GIT_DIFF_STATS_FULL: int
GIT_DIFF_STATS_INCLUDE_SUMMARY: int
GIT_DIFF_STATS_NONE: int
GIT_DIFF_STATS_NUMBER: int
GIT_DIFF_STATS_SHORT: int
GIT_DIFF_UPDATE_INDEX: int
GIT_FILEMODE_BLOB: int
GIT_FILEMODE_BLOB_EXECUTABLE: int
GIT_FILEMODE_COMMIT: int
GIT_FILEMODE_LINK: int
GIT_FILEMODE_TREE: int
GIT_FILEMODE_UNREADABLE: int
GIT_FILTER_ALLOW_UNSAFE: int
GIT_FILTER_ATTRIBUTES_FROM_COMMIT: int
GIT_FILTER_ATTRIBUTES_FROM_HEAD: int
GIT_FILTER_CLEAN: int
GIT_FILTER_DEFAULT: int
GIT_FILTER_DRIVER_PRIORITY: int
GIT_FILTER_NO_SYSTEM_ATTRIBUTES: int
GIT_FILTER_SMUDGE: int
GIT_FILTER_TO_ODB: int
GIT_FILTER_TO_WORKTREE: int
GIT_MERGE_ANALYSIS_FASTFORWARD: int
GIT_MERGE_ANALYSIS_NONE: int
GIT_MERGE_ANALYSIS_NORMAL: int
GIT_MERGE_ANALYSIS_UNBORN: int
GIT_MERGE_ANALYSIS_UP_TO_DATE: int
GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY: int
GIT_MERGE_PREFERENCE_NONE: int
GIT_MERGE_PREFERENCE_NO_FASTFORWARD: int
GIT_OBJECT_ANY: int
GIT_OBJECT_BLOB: int
GIT_OBJECT_COMMIT: int
GIT_OBJECT_INVALID: int
GIT_OBJECT_OFS_DELTA: int
GIT_OBJECT_REF_DELTA: int
GIT_OBJECT_TAG: int
GIT_OBJECT_TREE: int
GIT_OBJ_ANY: int
GIT_OBJ_BLOB: int
GIT_OBJ_COMMIT: int
GIT_OBJ_TAG: int
GIT_OBJ_TREE: int
GIT_OID_HEXSZ: int
GIT_OID_HEX_ZERO: str
GIT_OID_MINPREFIXLEN: int
GIT_OID_RAWSZ: int
GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS: int
GIT_OPT_ENABLE_CACHING: int
GIT_OPT_ENABLE_FSYNC_GITDIR: int
GIT_OPT_ENABLE_OFS_DELTA: int
GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION: int
GIT_OPT_ENABLE_STRICT_OBJECT_CREATION: int
GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION: int
GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY: int
GIT_OPT_GET_CACHED_MEMORY: int
GIT_OPT_GET_MWINDOW_MAPPED_LIMIT: int
GIT_OPT_GET_MWINDOW_SIZE: int
GIT_OPT_GET_OWNER_VALIDATION: int
GIT_OPT_GET_PACK_MAX_OBJECTS: int
GIT_OPT_GET_SEARCH_PATH: int
GIT_OPT_GET_TEMPLATE_PATH: int
GIT_OPT_GET_USER_AGENT: int
GIT_OPT_GET_WINDOWS_SHAREMODE: int
GIT_OPT_SET_ALLOCATOR: int
GIT_OPT_SET_CACHE_MAX_SIZE: int
GIT_OPT_SET_CACHE_OBJECT_LIMIT: int
GIT_OPT_SET_MWINDOW_MAPPED_LIMIT: int
GIT_OPT_SET_MWINDOW_SIZE: int
GIT_OPT_SET_OWNER_VALIDATION: int
GIT_OPT_SET_PACK_MAX_OBJECTS: int
GIT_OPT_SET_SEARCH_PATH: int
GIT_OPT_SET_SSL_CERT_LOCATIONS: int
GIT_OPT_SET_SSL_CIPHERS: int
GIT_OPT_SET_TEMPLATE_PATH: int
GIT_OPT_SET_USER_AGENT: int
GIT_OPT_SET_WINDOWS_SHAREMODE: int
GIT_REFERENCES_ALL: int
GIT_REFERENCES_BRANCHES: int
GIT_REFERENCES_TAGS: int
GIT_REF_INVALID: int
GIT_REF_LISTALL: int
GIT_REF_OID: int
GIT_REF_SYMBOLIC: int
GIT_RESET_HARD: int
GIT_RESET_MIXED: int
GIT_RESET_SOFT: int
GIT_REVPARSE_MERGE_BASE: int
GIT_REVPARSE_RANGE: int
GIT_REVPARSE_SINGLE: int
GIT_REVSPEC_MERGE_BASE: int
GIT_REVSPEC_RANGE: int
GIT_REVSPEC_SINGLE: int
GIT_SORT_NONE: int
GIT_SORT_REVERSE: int
GIT_SORT_TIME: int
GIT_SORT_TOPOLOGICAL: int
GIT_STASH_APPLY_DEFAULT: int
GIT_STASH_APPLY_REINSTATE_INDEX: int
GIT_STASH_DEFAULT: int
GIT_STASH_INCLUDE_IGNORED: int
GIT_STASH_INCLUDE_UNTRACKED: int
GIT_STASH_KEEP_ALL: int
GIT_STASH_KEEP_INDEX: int
GIT_STATUS_CONFLICTED: int
GIT_STATUS_CURRENT: int
GIT_STATUS_IGNORED: int
GIT_STATUS_INDEX_DELETED: int
GIT_STATUS_INDEX_MODIFIED: int
GIT_STATUS_INDEX_NEW: int
GIT_STATUS_INDEX_RENAMED: int
GIT_STATUS_INDEX_TYPECHANGE: int
GIT_STATUS_WT_DELETED: int
GIT_STATUS_WT_MODIFIED: int
GIT_STATUS_WT_NEW: int
GIT_STATUS_WT_RENAMED: int
GIT_STATUS_WT_TYPECHANGE: int
GIT_STATUS_WT_UNREADABLE: int
GIT_SUBMODULE_IGNORE_ALL: int
GIT_SUBMODULE_IGNORE_DIRTY: int
GIT_SUBMODULE_IGNORE_NONE: int
GIT_SUBMODULE_IGNORE_UNSPECIFIED: int
GIT_SUBMODULE_IGNORE_UNTRACKED: int
GIT_SUBMODULE_STATUS_INDEX_ADDED: int
GIT_SUBMODULE_STATUS_INDEX_DELETED: int
GIT_SUBMODULE_STATUS_INDEX_MODIFIED: int
GIT_SUBMODULE_STATUS_IN_CONFIG: int
GIT_SUBMODULE_STATUS_IN_HEAD: int
GIT_SUBMODULE_STATUS_IN_INDEX: int
GIT_SUBMODULE_STATUS_IN_WD: int
GIT_SUBMODULE_STATUS_WD_ADDED: int
GIT_SUBMODULE_STATUS_WD_DELETED: int
GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED: int
GIT_SUBMODULE_STATUS_WD_MODIFIED: int
GIT_SUBMODULE_STATUS_WD_UNINITIALIZED: int
GIT_SUBMODULE_STATUS_WD_UNTRACKED: int
GIT_SUBMODULE_STATUS_WD_WD_MODIFIED: int
LIBGIT2_VERSION: str
LIBGIT2_VER_MAJOR: int
LIBGIT2_VER_MINOR: int
LIBGIT2_VER_REVISION: int
_GIT_OBJ_BLOB: TypeAlias = Literal[3]
_GIT_OBJ_COMMIT: TypeAlias = Literal[1]
_GIT_OBJ_TAG: TypeAlias = Literal[4]
_GIT_OBJ_TREE: TypeAlias = Literal[2]
class Object:
_pointer: bytes
filemode: FileMode
hex: str
id: Oid
name: str | None
oid: Oid
raw_name: bytes | None
short_id: str
type: Literal[_GIT_OBJ_COMMIT, _GIT_OBJ_TREE, _GIT_OBJ_TAG, _GIT_OBJ_BLOB]
type_str: Literal["commit", "tree", "tag", "blob"]
@overload
def peel(self, target_type: Literal[_GIT_OBJ_COMMIT]) -> Commit: ...
@overload
def peel(self, target_type: Literal[_GIT_OBJ_TREE]) -> Tree: ...
@overload
def peel(self, target_type: Literal[_GIT_OBJ_TAG]) -> Tag: ...
@overload
def peel(self, target_type: Literal[_GIT_OBJ_BLOB]) -> Blob: ...
@overload
def peel(self, target_type: None) -> Commit | Tree | Blob: ...
def read_raw(self) -> bytes: ...
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...
def __le__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
@final
class Reference:
name: str
raw_name: bytes
raw_shorthand: bytes
raw_target: Oid | bytes
shorthand: str
target: Oid | str
type: ReferenceType
@overload
def __init__(self, name: str, target: str) -> None: ...
@overload
def __init__(self, name: str, oid: Oid, peel: Oid) -> None: ...
def delete(self) -> None: ...
def log(self) -> Iterator[RefLogEntry]: ...
@overload
def peel(self, type: Literal[_GIT_OBJ_COMMIT]) -> Commit: ...
@overload
def peel(self, type: Literal[_GIT_OBJ_TREE]) -> Tree: ...
@overload
def peel(self, type: Literal[_GIT_OBJ_TAG]) -> Tag: ...
@overload
def peel(self, type: Literal[_GIT_OBJ_BLOB]) -> Blob: ...
@overload
def peel(self, type: None) -> Commit | Tree | Blob: ...
def rename(self, new_name: str) -> None: ...
def resolve(self) -> Reference: ...
def set_target(self, target: _OidArg, message: str = ...) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
def __le__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
class AlreadyExistsError(ValueError): ...
@final
class Blob(Object):
data: bytes
is_binary: bool
size: int
def diff(self, blob: Blob = ..., flag: int = ..., old_as_path: str = ..., new_as_path: str = ...) -> Patch: ...
def diff_to_buffer(
self, buffer: bytes | None = None, flag: DiffOption = ..., old_as_path: str = ..., buffer_as_path: str = ...
) -> Patch: ...
# This is not a real subclassing. Just ensuring type-checkers sees this type as compatible with _CDataBase
# pyright has no error code for subclassing final
@final
class Branch(Reference): # type: ignore[misc] # pyright: ignore
branch_name: str
raw_branch_name: bytes
remote_name: str
upstream: Branch
upstream_name: str
def delete(self) -> None: ...
def is_checked_out(self) -> bool: ...
def is_head(self) -> bool: ...
def rename(self, name: str, force: bool = False) -> None: ...
@final
class Commit(Object):
author: Signature
commit_time: int
commit_time_offset: int
committer: Signature
gpg_signature: tuple[bytes, bytes]
message: str
message_encoding: str
message_trailers: dict[str, str]
parent_ids: list[Oid]
parents: list[Commit]
raw_message: bytes
tree: Tree
tree_id: Oid
class Diff:
deltas: Iterator[DiffDelta]
patch: str | None
patchid: Oid
stats: DiffStats
def find_similar(
self,
flags: DiffFind = ...,
rename_threshold: int = 50,
copy_threshold: int = 50,
rename_from_rewrite_threshold: int = 50,
break_rewrite_threshold: int = 60,
rename_limit: int = 1000,
) -> None: ...
def merge(self, diff: Diff) -> None: ...
@staticmethod
def from_c(diff: bytes, repo: Repository) -> Diff: ...
@staticmethod
def parse_diff(git_diff: str | bytes) -> Diff: ...
def __getitem__(self, index: int) -> Patch: ... # Diff_getitem
def __iter__(self) -> Iterator[Patch]: ... # -> DiffIter
def __len__(self) -> int: ...
@final
class DiffDelta:
flags: DiffFlag
is_binary: bool
nfiles: int
new_file: DiffFile
old_file: DiffFile
similarity: int
status: FileStatus
def status_char(self) -> str: ...
@final
class DiffFile:
flags: DiffFlag
id: Oid
mode: FileMode
path: str
raw_path: bytes
size: int
@staticmethod
def from_c(ptr: bytes) -> DiffFile: ...
class DiffHunk:
header: str
lines: list[DiffLine]
new_lines: int
new_start: int
old_lines: int
old_start: int
@final
class DiffLine:
content: str
content_offset: int
new_lineno: int
num_lines: int
old_lineno: int
origin: str
raw_content: bytes
class DiffStats:
deletions: int
files_changed: int
insertions: int
def format(self, format: DiffStatsFormat, width: int) -> str: ...
@final
class FilterSource:
repo: Repository
path: str
filemode: int
oid: Oid
mode: int
flags: int
class GitError(Exception): ...
class InvalidSpecError(ValueError): ...
@final
class Mailmap:
def __init__(self) -> None: ...
def add_entry(
self, real_name: str = ..., real_email: str = ..., replace_name: str = ..., replace_email: str = ...
) -> None: ...
@staticmethod
def from_buffer(buffer: str | bytes) -> Mailmap: ...
@staticmethod
def from_repository(repository: Repository) -> Mailmap: ...
def resolve(self, name: str, email: str) -> tuple[str, str]: ...
def resolve_signature(self, sig: Signature) -> Signature: ...
@final
class Note:
annotated_id: Oid
id: Oid
message: str
def remove(self, author: Signature, committer: Signature, ref: str = "refs/notes/commits") -> None: ...
@final
class Odb:
backends: Iterator[OdbBackend]
def __init__(self, path: StrOrBytesPath | None = None) -> None: ...
def add_backend(self, backend: OdbBackend, priority: int) -> None: ...
def add_disk_alternate(self, path: str) -> None: ...
def exists(self, oid: _OidArg) -> bool: ...
def read(self, oid: _OidArg) -> tuple[int, int, bytes]: ...
def write(self, type: int, data: bytes) -> Oid: ...
def __contains__(self, other: _OidArg) -> bool: ...
def __iter__(self) -> Iterator[Oid]: ... # Odb_as_iter
class OdbBackend:
def __init__(self) -> None: ...
def exists(self, oid: _OidArg) -> bool: ...
def exists_prefix(self, partial_id: _OidArg) -> Oid: ...
def read(self, oid: _OidArg) -> tuple[int, bytes]: ...
def read_header(self, oid: _OidArg) -> tuple[int, int]: ...
def read_prefix(self, oid: _OidArg) -> tuple[int, bytes, Oid]: ...
def refresh(self) -> None: ...
def __iter__(self) -> Iterator[Oid]: ... # OdbBackend_as_iter
@final
class OdbBackendLoose(OdbBackend):
def __init__(
self, objects_dir: StrOrBytesPath, compression_level: int, do_fsync: bool, dir_mode: int = 0, file_mode: int = 0
) -> None: ...
@final
class OdbBackendPack(OdbBackend):
def __init__(self, path: StrOrBytesPath) -> None: ...
@final
class Oid:
hex: str
raw: bytes
def __init__(self, raw: bytes = ..., hex: str = ...) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...
def __le__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
@final
class Patch:
data: bytes
delta: DiffDelta
hunks: list[DiffHunk]
line_stats: tuple[int, int, int] # context, additions, deletions
text: str | None
@staticmethod
def create_from(
old: Blob | bytes | None,
new: Blob | bytes | None,
old_as_path: str = ...,
new_as_path: str = ...,
flag: DiffOption = ...,
context_lines: int = 3,
interhunk_lines: int = 0,
) -> Patch: ...
@final
class RefLogEntry:
committer: Signature
message: str
oid_new: Oid
oid_old: Oid
@final
class Refdb:
def compress(self) -> None: ...
@staticmethod
def new(repo: Repository) -> Refdb: ...
@staticmethod
def open(repo: Repository) -> Refdb: ...
def set_backend(self, backend: RefdbBackend) -> None: ...
class RefdbBackend:
def __init__(self) -> None: ...
def compress(self) -> None: ...
def delete(self, ref_name: str, old_id: _OidArg, old_target: str) -> None: ...
def ensure_log(self, ref_name: str) -> bool: ...
def exists(self, refname: str) -> bool: ...
def has_log(self, ref_name: str) -> bool: ...
def lookup(self, refname: str) -> Reference: ...
def rename(self, old_name: str, new_name: str, force: bool, who: Signature, message: str) -> Reference: ...
def write(self, ref: Reference, force: bool, who: Signature, message: str, old: _OidArg, old_target: str) -> None: ...
@final
class RefdbFsBackend(RefdbBackend):
def __init__(self, repo: Repository) -> None: ...
class Repository:
_pointer: bytes
default_signature: Signature
head: Reference
head_is_detached: bool
head_is_unborn: bool
is_bare: bool
is_empty: bool
is_shallow: bool
odb: Odb
path: str
refdb: Refdb
workdir: str
def __init__(self, backend: object | None = None) -> None: ...
def TreeBuilder(self, src: Tree | _OidArg = ...) -> TreeBuilder: ...
def _disown(self) -> None: ...
def _from_c(self, pointer: bytes, free: bool) -> None: ...
def add_worktree(self, name: str, path: str, ref: Reference = ...) -> Worktree: ...
def applies(self, diff: Diff, location: ApplyLocation = ..., raise_error: bool = False) -> bool: ...
def apply(self, diff: Diff, location: ApplyLocation = ...) -> None: ...
def cherrypick(self, id: _OidArg) -> None: ...
def compress_references(self) -> None: ...
def create_blob(self, data: bytes) -> Oid: ...
def create_blob_fromdisk(self, path: str) -> Oid: ...
def create_blob_fromiobase(self, iobase: IOBase) -> Oid: ...
def create_blob_fromworkdir(self, path: str) -> Oid: ...
def create_branch(self, name: str, commit: Commit, force: bool = False) -> Branch: ...
def create_commit(
self,
reference_name: str | None,
author: Signature,
committer: Signature,
message: str | bytes,
tree: _OidArg,
parents: list[_OidArg],
encoding: str = ...,
) -> Oid: ...
def create_commit_string(
self,
author: Signature,
committer: Signature,
message: str | bytes,
tree: _OidArg,
parents: list[_OidArg],
encoding: str = ...,
) -> Oid: ...
def create_commit_with_signature(self, content: str, signature: str, signature_field: str | None = None) -> Oid: ...
def create_note(
self,
message: str,
author: Signature,
committer: Signature,
annotated_id: str,
ref: str = "refs/notes/commits",
force: bool = False,
) -> Oid: ...
def create_reference_direct(self, name: str, target: _OidArg, force: bool, message: str | None = None) -> Reference: ...
def create_reference_symbolic(self, name: str, target: str, force: bool, message: str | None = None) -> Reference: ...
def create_tag(self, name: str, oid: _OidArg, type: ObjectType, tagger: Signature, message: str) -> Oid: ...
def descendant_of(self, oid1: _OidArg, oid2: _OidArg) -> bool: ...
def expand_id(self, hex: str) -> Oid: ...
def free(self) -> None: ...
def git_object_lookup_prefix(self, oid: _OidArg) -> Object: ...
def list_worktrees(self) -> list[str]: ...
def listall_branches(self, flag: BranchType = ...) -> list[str]: ...
def listall_mergeheads(self) -> list[Oid]: ...
def listall_stashes(self) -> list[Stash]: ...
def listall_submodules(self) -> list[str]: ...
def lookup_branch(self, branch_name: str, branch_type: BranchType = ...) -> Branch: ...
def lookup_note(self, annotated_id: str, ref: str = "refs/notes/commits") -> Note: ...
def lookup_reference(self, name: str) -> Reference: ...
def lookup_reference_dwim(self, name: str) -> Reference: ...
def lookup_worktree(self, name: str) -> Worktree: ...
def merge_analysis(self, their_head: _OidArg, our_ref: str = "HEAD") -> tuple[MergeAnalysis, MergePreference]: ...
def merge_base(self, oid1: _OidArg, oid2: _OidArg) -> Oid: ...
def merge_base_many(self, oids: list[_OidArg]) -> Oid: ...
def merge_base_octopus(self, oids: list[_OidArg]) -> Oid: ...
def notes(self) -> Iterator[Note]: ...
def path_is_ignored(self, path: str) -> bool: ...
def raw_listall_branches(self, flag: BranchType = ...) -> list[bytes]: ...
def raw_listall_references(self) -> list[bytes]: ...
def references_iterator_init(self) -> Iterator[Reference]: ...
def references_iterator_next(self, iter: Iterator[Reference], references_return_type: ReferenceFilter = ...) -> Reference: ...
def reset(self, oid: _OidArg, reset_type: ResetMode) -> None: ...
def revparse(self, revspec: str) -> RevSpec: ...
def revparse_ext(self, revision: str) -> tuple[Object, Reference]: ...
def revparse_single(self, revision: str) -> Object: ...
def set_odb(self, odb: Odb) -> None: ...
def set_refdb(self, refdb: Refdb) -> None: ...
def status(self, untracked_files: str = "all", ignored: bool = False) -> dict[str, int]: ...
def status_file(self, path: str) -> int: ...
def walk(self, oid: _OidArg | None, sort_mode: SortMode = ...) -> Walker: ...
class RevSpec:
flags: int
from_object: Object
to_object: Object
@final
class Signature:
_encoding: str | None
_pointer: bytes
email: str
name: str
offset: int
raw_email: bytes
raw_name: bytes
time: int
def __init__(self, name: str, email: str, time: int = -1, offset: int = 0, encoding: str | None = None) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
def __le__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
@final
class Stash:
commit_id: Oid
message: str
raw_message: bytes
def __eq__(self, other: object) -> bool: ...
def __ge__(self, other: object) -> bool: ...
def __gt__(self, other: object) -> bool: ...
def __le__(self, other: object) -> bool: ...
def __lt__(self, other: object) -> bool: ...
def __ne__(self, other: object) -> bool: ...
@final
class Tag(Object):
message: str
name: str
raw_message: bytes
raw_name: bytes
tagger: Signature
target: Oid
def get_object(self) -> Object: ...
class Tree(Object):
def diff_to_index(self, index: Index, flags: DiffOption = ..., context_lines: int = 3, interhunk_lines: int = 0) -> Diff: ...
def diff_to_tree(
self, tree: Tree = ..., flags: DiffOption = ..., context_lines: int = 3, interhunk_lines: int = 3, swap: bool = False
) -> Diff: ...
def diff_to_workdir(self, flags: DiffOption = ..., context_lines: int = 3, interhunk_lines: int = 0) -> Diff: ...
def __contains__(self, other: str) -> bool: ... # Tree_contains
def __getitem__(self, index: str | int) -> Object: ... # Tree_subscript
def __iter__(self) -> Iterator[Object]: ...
def __len__(self) -> int: ... # Tree_len
def __rtruediv__(self, other: str) -> Object: ...
def __truediv__(self, other: str) -> Object: ... # Tree_divide
class TreeBuilder:
def clear(self) -> None: ...
def get(self, name: str) -> Object: ...
def insert(self, name: str, oid: _OidArg, attr: int) -> None: ...
def remove(self, name: str) -> None: ...
def write(self) -> Oid: ...
def __len__(self) -> int: ...
@final
class Walker:
def hide(self, oid: _OidArg) -> None: ...
def push(self, oid: _OidArg) -> None: ...
def reset(self) -> None: ...
def simplify_first_parent(self) -> None: ...
def sort(self, mode: SortMode) -> None: ...
def __iter__(self) -> Iterator[Commit]: ... # Walker: ...
def __next__(self) -> Commit: ...
@final
class Worktree:
is_prunable: bool
name: str
path: str
def prune(self, force: bool = False) -> None: ...
def discover_repository(path: str, across_fs: bool = False, ceiling_dirs: str = ...) -> str: ...
def filter_register(name: str, filter_cls: type[Filter], priority: int = ...) -> None: ...
def filter_unregister(name: str) -> None: ...
def hash(data: bytes) -> Oid: ...
def hashfile(path: str) -> Oid: ...
def init_file_backend(path: str, flags: int = 0) -> object: ...
def option(opt: Option, *args: Any) -> int | str | tuple[int, int] | None: ...
def reference_is_valid_name(refname: str) -> bool: ...
def tree_entry_cmp(a: Object, b: Object) -> int: ...
def _cache_enums() -> None: ... # undocumented
_OidArg: TypeAlias = str | Oid

View File

@@ -0,0 +1,15 @@
from _typeshed import Incomplete
from pathlib import Path
from cffi import FFI
dir_path: Path
h_files: list[str]
h_source: list[str]
h_file: Path
f: Incomplete
C_HEADER_SRC: str
C_PREAMBLE: str
_: Path
libgit2_kw: dict[str, list[str]]
ffi: FFI

View File

@@ -0,0 +1,34 @@
from collections.abc import Iterator
from _cffi_backend import _CDataBase
from ._pygit2 import Oid, Signature
def wrap_signature(csig: _CDataBase) -> Signature: ...
class BlameHunk:
@property
def lines_in_hunk(self) -> int: ...
@property
def boundary(self) -> bool: ...
@property
def final_start_line_number(self) -> int: ...
@property
def final_committer(self) -> Signature: ...
@property
def final_commit_id(self) -> Oid: ...
@property
def orig_start_line_number(self) -> int: ...
@property
def orig_committer(self) -> Signature: ...
@property
def orig_commit_id(self) -> Oid: ...
@property
def orig_path(self) -> str | None: ...
class Blame:
def __del__(self) -> None: ...
def __len__(self) -> int: ...
def __getitem__(self, index: int) -> BlameHunk: ...
def for_line(self, line_no: int) -> BlameHunk: ...
def __iter__(self) -> Iterator[BlameHunk]: ...

View File

@@ -0,0 +1,25 @@
import io
import types
from _typeshed import WriteableBuffer
from contextlib import AbstractContextManager
from ._pygit2 import Blob, Oid
from .enums import BlobFilter
class _BlobIO(io.RawIOBase):
def __init__(self, blob: Blob, as_path: str | None = None, flags: BlobFilter = ..., commit_id: Oid | None = None) -> None: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None
) -> None: ...
def isatty() -> bool: ... # type: ignore[misc]
def readable(self) -> bool: ...
def writable(self) -> bool: ...
def seekable(self) -> bool: ...
def readinto(self, b: WriteableBuffer, /) -> int: ...
def close(self) -> None: ...
class BlobIO(io.BufferedReader, AbstractContextManager[_BlobIO]): # type: ignore[misc]
def __init__(self, blob: Blob, as_path: str | None = None, flags: BlobFilter = ..., commit_id: Oid | None = None) -> None: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None
) -> None: ...

View File

@@ -0,0 +1,17 @@
from collections.abc import Iterator
from ._pygit2 import Branch, Commit, Oid
from .enums import BranchType
from .repository import BaseRepository
class Branches:
local: Branches
remote: Branches
def __init__(self, repository: BaseRepository, flag: BranchType = ..., commit: Commit | Oid | None = None) -> None: ...
def __getitem__(self, name: str) -> Branch: ...
def get(self, key: str) -> Branch | None: ...
def __iter__(self) -> Iterator[str]: ...
def create(self, name: str, commit: Commit, force: bool = False) -> Branch: ...
def delete(self, name: str) -> None: ...
def with_commit(self, commit: Commit | Oid | None) -> Branches: ...
def __contains__(self, name: str) -> bool: ...

View File

@@ -0,0 +1,78 @@
from _typeshed import StrOrBytesPath
from collections.abc import Callable
from contextlib import AbstractContextManager
from typing import Protocol
from typing_extensions import ParamSpec, Self, TypeAlias
from _cffi_backend import _CDataBase
from ._pygit2 import DiffFile, Oid
from .enums import CheckoutNotify, CheckoutStrategy, CredentialType, StashApplyProgress
from .remotes import TransferProgress
from .utils import _IntoStrArray
class Payload:
def __init__(self, **kw: object) -> None: ...
def check_error(self, error_code: int) -> None: ...
# Upstream is not yet defining a concrete type for certificates, and no usage example is
# available either.
_Certificate: TypeAlias = None
class _Credentials(Protocol):
@property
def credential_type(self) -> CredentialType: ...
@property
def credential_tuple(self) -> tuple[str, ...]: ...
def __call__(self, _url: str, _username: str | None, _allowed: CredentialType) -> Self: ...
class RemoteCallbacks(Payload):
# Upstream code is broken: the credentials() method is shadowed if the constructor
# gets passed a non-None "credentials".
# credentials: _Credentials | None
certificate: _Certificate | None
def __init__(self, credentials: _Credentials | None = None, certificate: _Certificate | None = None) -> None: ...
def sideband_progress(self, string: str) -> None: ...
def credentials(self, url: str, username_from_url: str | None, allowed_types: CredentialType) -> _Credentials: ...
def certificate_check(self, certificate: _Certificate, valid: bool, host: str) -> bool: ...
def transfer_progress(self, stats: TransferProgress) -> None: ...
def update_tips(self, refname: str, old: Oid, new: Oid) -> None: ...
def push_update_reference(self, refname: str, message: str) -> None: ...
class CheckoutCallbacks(Payload):
def __init__(self) -> None: ...
def checkout_notify_flags(self) -> CheckoutNotify: ...
def checkout_notify(
self, why: CheckoutNotify, path: str, baseline: DiffFile | None, target: DiffFile | None, workdir: DiffFile | None
) -> None: ...
def checkout_progress(self, path: str, completed_steps: int, total_steps: int) -> None: ...
class StashApplyCallbacks(CheckoutCallbacks):
def stash_apply_progress(self, progress: StashApplyProgress) -> None: ...
def git_clone_options(payload: Payload, opts: _CDataBase | None = None) -> AbstractContextManager[Payload]: ...
def git_fetch_options(payload: Payload, opts: _CDataBase | None = None) -> AbstractContextManager[Payload]: ...
def git_push_options(payload: Payload, opts: _CDataBase | None = None) -> AbstractContextManager[Payload]: ...
def git_remote_callbacks(payload: Payload) -> AbstractContextManager[Payload]: ...
_P = ParamSpec("_P")
def libgit2_callback(f: Callable[_P, int]) -> Callable[_P, int]: ...
def libgit2_callback_void(f: Callable[_P, None]) -> Callable[_P, None]: ...
_CredentialsFn: TypeAlias = Callable[[str | None, str | None, CredentialType], _Credentials]
def get_credentials(fn: _CredentialsFn, url: _CDataBase, username: _CDataBase, allowed: CredentialType) -> _CDataBase: ...
def git_checkout_options(
callbacks: CheckoutCallbacks | None = None,
strategy: CheckoutStrategy | None = None,
directory: StrOrBytesPath | None = None,
paths: _IntoStrArray = None,
) -> AbstractContextManager[Payload]: ...
def git_stash_apply_options(
callbacks: StashApplyCallbacks | None = None,
reinstate_index: bool = False,
strategy: CheckoutStrategy | None = None,
directory: StrOrBytesPath | None = None,
paths: _IntoStrArray = None,
) -> AbstractContextManager[Payload]: ...

View File

@@ -0,0 +1,59 @@
from _typeshed import StrOrBytesPath
from typing_extensions import Self
from _cffi_backend import _CDataBase
def str_to_bytes(value: str, name: object) -> bytes: ...
class ConfigIterator:
def __init__(self, config: _CDataBase, ptr: _CDataBase) -> None: ...
def __del__(self) -> None: ...
def __iter__(self) -> Self: ...
def next(self) -> ConfigEntry: ...
def __next__(self) -> ConfigEntry: ...
class ConfigMultivarIterator(ConfigIterator):
def __next__(self) -> str: ... # type: ignore[override]
class Config:
def __init__(self, path: str | None = None) -> None: ...
@classmethod
def from_c(cls, repo: _CDataBase, ptr: _CDataBase) -> Config: ...
def __del__(self) -> None: ...
def __contains__(self, key: str) -> bool: ...
def __getitem__(self, key: str) -> str: ...
def __setitem__(self, key: str, value: bool | int | _CDataBase | StrOrBytesPath | None) -> None: ...
def __delitem__(self, key: str) -> None: ...
def __iter__(self) -> ConfigIterator: ...
def get_multivar(self, name: str, regex: str | None = None) -> ConfigMultivarIterator: ...
def set_multivar(self, name: str, regex: str, value: str) -> None: ...
def delete_multivar(self, name: str, regex: str) -> None: ...
def get_bool(self, key: str) -> bool: ...
def get_int(self, key: str) -> int: ...
def add_file(self, path: StrOrBytesPath, level: int = 0, force: int = 0) -> None: ...
def snapshot(self) -> Config: ...
@staticmethod
def parse_bool(text: _CDataBase | bytes | str | None) -> bool: ...
@staticmethod
def parse_int(text: _CDataBase | bytes | str | None) -> int: ...
@staticmethod
def get_system_config() -> Config: ...
@staticmethod
def get_global_config() -> Config: ...
@staticmethod
def get_xdg_config() -> Config: ...
class ConfigEntry:
def __del__(self) -> None: ...
@property
def c_value(self) -> _CDataBase: ...
@property
def raw_name(self) -> bytes: ...
@property
def raw_value(self) -> bytes: ...
@property
def level(self) -> int: ...
@property
def name(self) -> str: ...
@property
def value(self) -> str: ...

View File

@@ -0,0 +1,34 @@
from typing_extensions import Self
from .enums import CredentialType
class Username:
def __init__(self, username: str) -> None: ...
@property
def credential_type(self) -> CredentialType: ...
@property
def credential_tuple(self) -> tuple[str]: ...
def __call__(self, _url: str, _username: str | None, _allowed: CredentialType) -> Self: ...
class UserPass:
def __init__(self, username: str, password: str) -> None: ...
@property
def credential_type(self) -> CredentialType: ...
@property
def credential_tuple(self) -> tuple[str, str]: ...
def __call__(self, _url: str, _username: str | None, _allowed: CredentialType) -> Self: ...
class Keypair:
def __init__(self, username: str, pubkey: str, privkey: str, passphrase: str) -> None: ...
@property
def credential_type(self) -> CredentialType: ...
@property
def credential_tuple(self) -> tuple[str, str, str, str]: ...
def __call__(self, _url: str, _username: str | None, _allowed: CredentialType) -> Self: ...
class KeypairFromAgent(Keypair):
def __init__(self, username: str) -> None: ...
class KeypairFromMemory(Keypair):
@property
def credential_type(self) -> CredentialType: ...

View File

@@ -0,0 +1,395 @@
from enum import IntEnum, IntFlag
class ApplyLocation(IntEnum):
WORKDIR: int
INDEX: int
BOTH: int
class AttrCheck(IntFlag):
FILE_THEN_INDEX: int
INDEX_THEN_FILE: int
INDEX_ONLY: int
NO_SYSTEM: int
INCLUDE_HEAD: int
INCLUDE_COMMIT: int
class BlameFlag(IntFlag):
NORMAL: int
TRACK_COPIES_SAME_FILE: int
TRACK_COPIES_SAME_COMMIT_MOVES: int
TRACK_COPIES_SAME_COMMIT_COPIES: int
TRACK_COPIES_ANY_COMMIT_COPIES: int
FIRST_PARENT: int
USE_MAILMAP: int
IGNORE_WHITESPACE: int
class BlobFilter(IntFlag):
CHECK_FOR_BINARY: int
NO_SYSTEM_ATTRIBUTES: int
ATTRIBUTES_FROM_HEAD: int
ATTRIBUTES_FROM_COMMIT: int
class BranchType(IntFlag):
LOCAL: int
REMOTE: int
ALL: int
class CheckoutNotify(IntFlag):
NONE: int
CONFLICT: int
DIRTY: int
UPDATED: int
UNTRACKED: int
IGNORED: int
ALL: int
class CheckoutStrategy(IntFlag):
NONE: int
SAFE: int
FORCE: int
RECREATE_MISSING: int
ALLOW_CONFLICTS: int
REMOVE_UNTRACKED: int
REMOVE_IGNORED: int
UPDATE_ONLY: int
DONT_UPDATE_INDEX: int
NO_REFRESH: int
SKIP_UNMERGED: int
USE_OURS: int
USE_THEIRS: int
DISABLE_PATHSPEC_MATCH: int
SKIP_LOCKED_DIRECTORIES: int
DONT_OVERWRITE_IGNORED: int
CONFLICT_STYLE_MERGE: int
CONFLICT_STYLE_DIFF3: int
DONT_REMOVE_EXISTING: int
DONT_WRITE_INDEX: int
DRY_RUN: int
CONFLICT_STYLE_ZDIFF3: int
class ConfigLevel(IntEnum):
PROGRAMDATA: int
SYSTEM: int
XDG: int
GLOBAL: int
LOCAL: int
APP: int
HIGHEST_LEVEL: int
class CredentialType(IntFlag):
USERPASS_PLAINTEXT: int
SSH_KEY: int
SSH_CUSTOM: int
DEFAULT: int
SSH_INTERACTIVE: int
USERNAME: int
SSH_MEMORY: int
class DeltaStatus(IntEnum):
UNMODIFIED: int
ADDED: int
DELETED: int
MODIFIED: int
RENAMED: int
COPIED: int
IGNORED: int
UNTRACKED: int
TYPECHANGE: int
UNREADABLE: int
CONFLICTED: int
class DescribeStrategy(IntEnum):
DEFAULT: int
TAGS: int
ALL: int
class DiffFind(IntFlag):
FIND_BY_CONFIG: int
FIND_RENAMES: int
FIND_RENAMES_FROM_REWRITES: int
FIND_COPIES: int
FIND_COPIES_FROM_UNMODIFIED: int
FIND_REWRITES: int
BREAK_REWRITES: int
FIND_AND_BREAK_REWRITES: int
FIND_FOR_UNTRACKED: int
FIND_ALL: int
FIND_IGNORE_LEADING_WHITESPACE: int
FIND_IGNORE_WHITESPACE: int
FIND_DONT_IGNORE_WHITESPACE: int
FIND_EXACT_MATCH_ONLY: int
BREAK_REWRITES_FOR_RENAMES_ONLY: int
FIND_REMOVE_UNMODIFIED: int
class DiffFlag(IntFlag):
BINARY: int
NOT_BINARY: int
VALID_ID: int
EXISTS: int
VALID_SIZE: int
class DiffOption(IntFlag):
NORMAL: int
REVERSE: int
INCLUDE_IGNORED: int
RECURSE_IGNORED_DIRS: int
INCLUDE_UNTRACKED: int
RECURSE_UNTRACKED_DIRS: int
INCLUDE_UNMODIFIED: int
INCLUDE_TYPECHANGE: int
INCLUDE_TYPECHANGE_TREES: int
IGNORE_FILEMODE: int
IGNORE_SUBMODULES: int
IGNORE_CASE: int
INCLUDE_CASECHANGE: int
DISABLE_PATHSPEC_MATCH: int
SKIP_BINARY_CHECK: int
ENABLE_FAST_UNTRACKED_DIRS: int
UPDATE_INDEX: int
INCLUDE_UNREADABLE: int
INCLUDE_UNREADABLE_AS_UNTRACKED: int
INDENT_HEURISTIC: int
IGNORE_BLANK_LINES: int
FORCE_TEXT: int
FORCE_BINARY: int
IGNORE_WHITESPACE: int
IGNORE_WHITESPACE_CHANGE: int
IGNORE_WHITESPACE_EOL: int
SHOW_UNTRACKED_CONTENT: int
SHOW_UNMODIFIED: int
PATIENCE: int
MINIMAL: int
SHOW_BINARY: int
class DiffStatsFormat(IntFlag):
NONE: int
FULL: int
SHORT: int
NUMBER: int
INCLUDE_SUMMARY: int
class Feature(IntFlag):
THREADS: int
HTTPS: int
SSH: int
NSEC: int
class FetchPrune(IntEnum):
UNSPECIFIED: int
PRUNE: int
NO_PRUNE: int
class FileMode(IntFlag):
UNREADABLE: int
TREE: int
BLOB: int
BLOB_EXECUTABLE: int
LINK: int
COMMIT: int
class FileStatus(IntFlag):
CURRENT: int
INDEX_NEW: int
INDEX_MODIFIED: int
INDEX_DELETED: int
INDEX_RENAMED: int
INDEX_TYPECHANGE: int
WT_NEW: int
WT_MODIFIED: int
WT_DELETED: int
WT_TYPECHANGE: int
WT_RENAMED: int
WT_UNREADABLE: int
IGNORED: int
CONFLICTED: int
class FilterFlag(IntFlag):
DEFAULT: int
ALLOW_UNSAFE: int
NO_SYSTEM_ATTRIBUTES: int
ATTRIBUTES_FROM_HEAD: int
ATTRIBUTES_FROM_COMMIT: int
class FilterMode(IntEnum):
TO_WORKTREE: int
SMUDGE: int
TO_ODB: int
CLEAN: int
class MergeAnalysis(IntFlag):
NONE: int
NORMAL: int
UP_TO_DATE: int
FASTFORWARD: int
UNBORN: int
class MergeFavor(IntEnum):
NORMAL: int
OURS: int
THEIRS: int
UNION: int
class MergeFileFlag(IntFlag):
DEFAULT: int
STYLE_MERGE: int
STYLE_DIFF3: int
SIMPLIFY_ALNUM: int
IGNORE_WHITESPACE: int
IGNORE_WHITESPACE_CHANGE: int
IGNORE_WHITESPACE_EOL: int
DIFF_PATIENCE: int
DIFF_MINIMAL: int
STYLE_ZDIFF3: int
ACCEPT_CONFLICTS: int
class MergeFlag(IntFlag):
FIND_RENAMES: int
FAIL_ON_CONFLICT: int
SKIP_REUC: int
NO_RECURSIVE: int
VIRTUAL_BASE: int
class MergePreference(IntFlag):
NONE: int
NO_FASTFORWARD: int
FASTFORWARD_ONLY: int
class ObjectType(IntEnum):
ANY: int
INVALID: int
COMMIT: int
TREE: int
BLOB: int
TAG: int
OFS_DELTA: int
REF_DELTA: int
class Option(IntEnum):
GET_MWINDOW_SIZE: int
SET_MWINDOW_SIZE: int
GET_MWINDOW_MAPPED_LIMIT: int
SET_MWINDOW_MAPPED_LIMIT: int
GET_SEARCH_PATH: int
SET_SEARCH_PATH: int
SET_CACHE_OBJECT_LIMIT: int
SET_CACHE_MAX_SIZE: int
ENABLE_CACHING: int
GET_CACHED_MEMORY: int
GET_TEMPLATE_PATH: int
SET_TEMPLATE_PATH: int
SET_SSL_CERT_LOCATIONS: int
SET_USER_AGENT: int
ENABLE_STRICT_OBJECT_CREATION: int
ENABLE_STRICT_SYMBOLIC_REF_CREATION: int
SET_SSL_CIPHERS: int
GET_USER_AGENT: int
ENABLE_OFS_DELTA: int
ENABLE_FSYNC_GITDIR: int
GET_WINDOWS_SHAREMODE: int
SET_WINDOWS_SHAREMODE: int
ENABLE_STRICT_HASH_VERIFICATION: int
SET_ALLOCATOR: int
ENABLE_UNSAVED_INDEX_SAFETY: int
GET_PACK_MAX_OBJECTS: int
SET_PACK_MAX_OBJECTS: int
DISABLE_PACK_KEEP_FILE_CHECKS: int
GET_OWNER_VALIDATION: int
SET_OWNER_VALIDATION: int
class ReferenceFilter(IntEnum):
ALL: int
BRANCHES: int
TAGS: int
class ReferenceType(IntFlag):
INVALID: int
DIRECT: int
SYMBOLIC: int
ALL: int
OID: int
LISTALL: int
class RepositoryInitFlag(IntFlag):
BARE: int
NO_REINIT: int
NO_DOTGIT_DIR: int
MKDIR: int
MKPATH: int
EXTERNAL_TEMPLATE: int
RELATIVE_GITLINK: int
class RepositoryInitMode(IntEnum):
SHARED_UMASK: int
SHARED_GROUP: int
SHARED_ALL: int
class RepositoryOpenFlag(IntFlag):
DEFAULT: int
NO_SEARCH: int
CROSS_FS: int
BARE: int
NO_DOTGIT: int
FROM_ENV: int
class RepositoryState(IntEnum):
NONE: int
MERGE: int
REVERT: int
REVERT_SEQUENCE: int
CHERRYPICK: int
CHERRYPICK_SEQUENCE: int
BISECT: int
REBASE: int
REBASE_INTERACTIVE: int
REBASE_MERGE: int
APPLY_MAILBOX: int
APPLY_MAILBOX_OR_REBASE: int
class ResetMode(IntEnum):
SOFT: int
MIXED: int
HARD: int
class RevSpecFlag(IntFlag):
SINGLE: int
RANGE: int
MERGE_BASE: int
class SortMode(IntFlag):
NONE: int
TOPOLOGICAL: int
TIME: int
REVERSE: int
class StashApplyProgress(IntEnum):
NONE: int
LOADING_STASH: int
ANALYZE_INDEX: int
ANALYZE_MODIFIED: int
ANALYZE_UNTRACKED: int
CHECKOUT_UNTRACKED: int
CHECKOUT_MODIFIED: int
DONE: int
class SubmoduleIgnore(IntEnum):
UNSPECIFIED: int
NONE: int
UNTRACKED: int
DIRTY: int
ALL: int
class SubmoduleStatus(IntFlag):
IN_HEAD: int
IN_INDEX: int
IN_CONFIG: int
IN_WD: int
INDEX_ADDED: int
INDEX_DELETED: int
INDEX_MODIFIED: int
WD_UNINITIALIZED: int
WD_ADDED: int
WD_DELETED: int
WD_MODIFIED: int
WD_INDEX_MODIFIED: int
WD_WD_MODIFIED: int
WD_UNTRACKED: int

View File

@@ -0,0 +1,6 @@
value_errors: set[int]
def check_error(err: int, io: bool = False) -> None: ...
class Passthrough(Exception):
def __init__(self) -> None: ...

View File

@@ -0,0 +1 @@
from ._libgit2 import ffi as ffi

View File

@@ -0,0 +1,11 @@
from collections.abc import Callable
from ._pygit2 import FilterSource
class Filter:
attributes: str
@classmethod
def nattrs(cls) -> int: ...
def check(self, src: FilterSource, attr_values: list[str | None]) -> None: ...
def write(self, data: bytes, src: FilterSource, write_next: Callable[[bytes], None]) -> None: ...
def close(self, write_next: Callable[[bytes], None]) -> None: ...

View File

@@ -0,0 +1,58 @@
from _typeshed import StrOrBytesPath, StrPath
from collections.abc import Iterator
from typing_extensions import Self
from _cffi_backend import _CDataBase
from ._pygit2 import Diff, Oid, Tree
from .enums import DiffOption, FileMode
from .repository import BaseRepository
from .utils import _IntoStrArray
class Index:
def __init__(self, path: StrOrBytesPath | None = None) -> None: ...
@classmethod
def from_c(cls, repo: _CDataBase, ptr: _CDataBase) -> Index: ...
def __del__(self) -> None: ...
def __len__(self) -> int: ...
def __contains__(self, path: StrOrBytesPath | None) -> bool: ...
def __getitem__(self, key: StrPath | int) -> IndexEntry: ...
def __iter__(self) -> Iterator[IndexEntry]: ...
def read(self, force: bool = True) -> None: ...
def write(self) -> None: ...
def clear(self) -> None: ...
def read_tree(self, tree: str | Oid | Tree) -> None: ...
def write_tree(self, repo: BaseRepository | None = None) -> Oid: ...
def remove(self, path: StrOrBytesPath, level: int = 0) -> None: ...
def remove_all(self, pathspecs: _IntoStrArray) -> None: ...
def add_all(self, pathspecs: _IntoStrArray = None) -> None: ...
def add(self, path_or_entry: IndexEntry | StrPath) -> None: ...
def diff_to_workdir(self, flags: DiffOption = ..., context_lines: int = 3, interhunk_lines: int = 0) -> Diff: ...
def diff_to_tree(self, tree: Tree, flags: DiffOption = ..., context_lines: int = 3, interhunk_lines: int = 0) -> Diff: ...
@property
def conflicts(self) -> ConflictCollection | None: ...
class IndexEntry:
path: str
id: Oid
mode: FileMode
def __init__(self, path: str, object_id: Oid, mode: FileMode) -> None: ...
@property
def oid(self) -> Oid: ...
@property
def hex(self) -> str: ...
def __eq__(self, other: object) -> bool: ...
class ConflictCollection:
def __init__(self, index: Index) -> None: ...
def __getitem__(self, path: StrOrBytesPath) -> tuple[IndexEntry, IndexEntry, IndexEntry]: ...
def __delitem__(self, path: StrOrBytesPath) -> None: ...
def __iter__(self) -> ConflictIterator: ...
def __contains__(self, path: StrOrBytesPath) -> bool: ...
class ConflictIterator:
def __init__(self, index: Index) -> None: ...
def __del__(self) -> None: ...
def next(self) -> tuple[IndexEntry, IndexEntry, IndexEntry]: ...
def __next__(self) -> tuple[IndexEntry, IndexEntry, IndexEntry]: ...
def __iter__(self) -> Self: ...

View File

@@ -0,0 +1,62 @@
GIT_FEATURE_THREADS: int
GIT_FEATURE_HTTPS: int
GIT_FEATURE_SSH: int
GIT_FEATURE_NSEC: int
GIT_REPOSITORY_INIT_BARE: int
GIT_REPOSITORY_INIT_NO_REINIT: int
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR: int
GIT_REPOSITORY_INIT_MKDIR: int
GIT_REPOSITORY_INIT_MKPATH: int
GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE: int
GIT_REPOSITORY_INIT_RELATIVE_GITLINK: int
GIT_REPOSITORY_INIT_SHARED_UMASK: int
GIT_REPOSITORY_INIT_SHARED_GROUP: int
GIT_REPOSITORY_INIT_SHARED_ALL: int
GIT_REPOSITORY_OPEN_NO_SEARCH: int
GIT_REPOSITORY_OPEN_CROSS_FS: int
GIT_REPOSITORY_OPEN_BARE: int
GIT_REPOSITORY_OPEN_NO_DOTGIT: int
GIT_REPOSITORY_OPEN_FROM_ENV: int
GIT_REPOSITORY_STATE_NONE: int
GIT_REPOSITORY_STATE_MERGE: int
GIT_REPOSITORY_STATE_REVERT: int
GIT_REPOSITORY_STATE_REVERT_SEQUENCE: int
GIT_REPOSITORY_STATE_CHERRYPICK: int
GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE: int
GIT_REPOSITORY_STATE_BISECT: int
GIT_REPOSITORY_STATE_REBASE: int
GIT_REPOSITORY_STATE_REBASE_INTERACTIVE: int
GIT_REPOSITORY_STATE_REBASE_MERGE: int
GIT_REPOSITORY_STATE_APPLY_MAILBOX: int
GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE: int
GIT_ATTR_CHECK_FILE_THEN_INDEX: int
GIT_ATTR_CHECK_INDEX_THEN_FILE: int
GIT_ATTR_CHECK_INDEX_ONLY: int
GIT_ATTR_CHECK_NO_SYSTEM: int
GIT_ATTR_CHECK_INCLUDE_HEAD: int
GIT_ATTR_CHECK_INCLUDE_COMMIT: int
GIT_FETCH_PRUNE_UNSPECIFIED: int
GIT_FETCH_PRUNE: int
GIT_FETCH_NO_PRUNE: int
GIT_CHECKOUT_NOTIFY_NONE: int
GIT_CHECKOUT_NOTIFY_CONFLICT: int
GIT_CHECKOUT_NOTIFY_DIRTY: int
GIT_CHECKOUT_NOTIFY_UPDATED: int
GIT_CHECKOUT_NOTIFY_UNTRACKED: int
GIT_CHECKOUT_NOTIFY_IGNORED: int
GIT_CHECKOUT_NOTIFY_ALL: int
GIT_STASH_APPLY_PROGRESS_NONE: int
GIT_STASH_APPLY_PROGRESS_LOADING_STASH: int
GIT_STASH_APPLY_PROGRESS_ANALYZE_INDEX: int
GIT_STASH_APPLY_PROGRESS_ANALYZE_MODIFIED: int
GIT_STASH_APPLY_PROGRESS_ANALYZE_UNTRACKED: int
GIT_STASH_APPLY_PROGRESS_CHECKOUT_UNTRACKED: int
GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED: int
GIT_STASH_APPLY_PROGRESS_DONE: int
GIT_CREDENTIAL_USERPASS_PLAINTEXT: int
GIT_CREDENTIAL_SSH_KEY: int
GIT_CREDENTIAL_SSH_CUSTOM: int
GIT_CREDENTIAL_DEFAULT: int
GIT_CREDENTIAL_SSH_INTERACTIVE: int
GIT_CREDENTIAL_USERNAME: int
GIT_CREDENTIAL_SSH_MEMORY: int

View File

@@ -0,0 +1,15 @@
from _typeshed import StrOrBytesPath
from ._pygit2 import Oid
from .repository import BaseRepository
class PackBuilder:
def __init__(self, repo: BaseRepository) -> None: ...
def __del__(self) -> None: ...
def __len__(self) -> int: ...
def add(self, oid: Oid) -> None: ...
def add_recur(self, oid: Oid) -> None: ...
def set_threads(self, n_threads: int) -> int: ...
def write(self, path: StrOrBytesPath | None = None) -> None: ...
@property
def written_objects_count(self) -> int: ...

View File

@@ -0,0 +1,18 @@
from collections.abc import Iterator
from ._pygit2 import Oid, Reference
from .enums import ReferenceFilter
from .repository import BaseRepository
class References:
def __init__(self, repository: BaseRepository) -> None: ...
def __getitem__(self, name: str) -> Reference: ...
def get(self, key: str) -> Reference | None: ...
def __iter__(self) -> Iterator[Reference]: ...
def iterator(self, references_return_type: ReferenceFilter = ...) -> Iterator[Reference]: ...
def create(self, name: str, target: Oid | str, force: bool = False) -> Reference: ...
def delete(self, name: str) -> None: ...
def __contains__(self, name: str) -> bool: ...
@property
def objects(self) -> list[Reference]: ...
def compress(self) -> None: ...

View File

@@ -0,0 +1,18 @@
from _cffi_backend import _CDataBase
class Refspec:
def __init__(self, owner: _CDataBase, ptr: _CDataBase) -> None: ...
@property
def src(self) -> str: ...
@property
def dst(self) -> str: ...
@property
def force(self) -> bool: ...
@property
def string(self) -> str: ...
@property
def direction(self) -> int: ...
def src_matches(self, ref: str) -> bool: ...
def dst_matches(self, ref: str) -> bool: ...
def transform(self, ref: str) -> str: ...
def rtransform(self, ref: str) -> str: ...

View File

@@ -0,0 +1,78 @@
from collections.abc import Iterator
from typing import Literal, TypedDict
from typing_extensions import TypeAlias
from _cffi_backend import _CDataBase
from ._pygit2 import Oid
from .callbacks import RemoteCallbacks
from .enums import FetchPrune
from .refspec import Refspec
from .repository import BaseRepository
from .utils import _IntoStrArray
class TransferProgress:
total_objects: int
indexed_objects: int
received_objects: int
local_objects: int
total_deltas: int
indexed_deltas: int
received_bytes: int
def __init__(self, tp: _CDataBase) -> None: ...
_ProxySpec: TypeAlias = Literal[True] | str | None
class _LsRemotesResultEntry(TypedDict):
local: bool
loid: Oid | None
name: str | None
symref_target: str | None
oid: Oid
class Remote:
def __init__(self, repo: BaseRepository, ptr: _CDataBase) -> None: ...
def __del__(self) -> None: ...
@property
def name(self) -> str | None: ...
@property
def url(self) -> str | None: ...
@property
def push_url(self) -> str | None: ...
def connect(self, callbacks: RemoteCallbacks | None = None, direction: int = 0, proxy: _ProxySpec = None) -> None: ...
def fetch(
self,
refspecs: _IntoStrArray = None,
message: bytes | str | None = None,
callbacks: RemoteCallbacks | None = None,
prune: FetchPrune = ...,
proxy: _ProxySpec = None,
depth: int = 0,
) -> TransferProgress: ...
def ls_remotes(self, callbacks: RemoteCallbacks | None = None, proxy: _ProxySpec = None) -> list[_LsRemotesResultEntry]: ...
def prune(self, callbacks: RemoteCallbacks | None = None) -> None: ...
@property
def refspec_count(self) -> int: ...
def get_refspec(self, n: int) -> Refspec: ...
@property
def fetch_refspecs(self) -> list[str]: ...
@property
def push_refspecs(self) -> list[str]: ...
def push(self, specs: _IntoStrArray, callbacks: RemoteCallbacks | None = None, proxy: _ProxySpec = None) -> None: ...
_RemoteName: TypeAlias = bytes | str
class RemoteCollection:
def __init__(self, repo: BaseRepository) -> None: ...
def __len__(self) -> int: ...
def __iter__(self) -> Iterator[Remote]: ...
def __getitem__(self, name: int | _RemoteName) -> Remote: ...
def names(self) -> Iterator[str | None]: ...
def create(self, name: _RemoteName, url: bytes | str, fetch: bytes | str | None = None) -> Remote: ...
def create_anonymous(self, url: bytes | str) -> Remote: ...
def rename(self, name: _RemoteName, new_name: bytes | str) -> list[str]: ...
def delete(self, name: _RemoteName) -> None: ...
def set_url(self, name: _RemoteName, url: bytes | str) -> None: ...
def set_push_url(self, name: _RemoteName, url: bytes | str) -> None: ...
def add_fetch(self, name: _RemoteName, refspec: bytes | str) -> None: ...
def add_push(self, name: _RemoteName, refspec: bytes | str) -> None: ...

View File

@@ -0,0 +1,212 @@
from _typeshed import StrOrBytesPath
from collections.abc import Callable, Iterable, Iterator
from tarfile import TarInfo
from typing import IO, Any, Protocol
from typing_extensions import TypeAlias, deprecated
from ._pygit2 import Blob, Commit, Diff, Object, Oid, Reference, Repository as _Repository, Signature, Tree, _OidArg
from .blame import Blame
from .callbacks import CheckoutCallbacks, RemoteCallbacks, StashApplyCallbacks
from .config import Config
from .enums import (
AttrCheck,
BlameFlag,
BranchType as BranchType,
CheckoutStrategy,
DescribeStrategy,
DiffOption,
MergeFavor,
MergeFileFlag,
MergeFlag,
RepositoryOpenFlag,
RepositoryState,
)
from .index import Index, IndexEntry
from .packbuilder import PackBuilder
from .submodules import Submodule
from .utils import _IntoStrArray
_PackDelegate: TypeAlias = Callable[[PackBuilder], None]
class _SupportsAddfile(Protocol):
def addfile(self, tarinfo: TarInfo, fileobj: IO[bytes] | None = None) -> None: ...
class BaseRepository(_Repository):
def __init__(self, *args: Any, **kwargs: Any) -> None: ... # not meant for direct use
def read(self, oid: _OidArg) -> tuple[int, int, bytes]: ...
def write(self, type: int, data: bytes) -> Oid: ...
def pack(
self, path: StrOrBytesPath | None = None, pack_delegate: _PackDelegate | None = None, n_threads: int | None = None
) -> int: ...
def __iter__(self) -> Iterator[Oid]: ...
@deprecated("Use repo.submodules.add(...)")
def add_submodule(self, url: str, path: str, link: bool = True, callbacks: RemoteCallbacks | None = None) -> Submodule: ...
@deprecated("Use repo.submodules[...]")
def lookup_submodule(self, path: str) -> Submodule: ...
@deprecated("Use repo.submodules.init(...)")
def init_submodules(self, submodules: Iterable[str] | None = None, overwrite: bool = False) -> None: ...
@deprecated("Use repo.submodules.update(...)")
def update_submodules(
self, submodules: Iterable[str] | None = None, init: bool = False, callbacks: RemoteCallbacks | None = None
) -> None: ...
def get(self, key: _OidArg, default: Object | None = None) -> Object | None: ...
def __getitem__(self, key: _OidArg) -> Object: ...
def __contains__(self, key: _OidArg) -> bool: ...
@property
def config(self) -> Config: ...
@property
def config_snapshot(self) -> Config: ...
def create_reference(self, name: str, target: _OidArg, force: bool = False, message: str | None = None) -> Reference: ...
def listall_references(self) -> list[str]: ...
def listall_reference_objects(self) -> list[Reference]: ...
def resolve_refish(self, refish: str) -> tuple[Commit, Reference]: ...
def checkout_head(
self,
*,
callbacks: CheckoutCallbacks | None = None,
strategy: CheckoutStrategy | None = None,
directory: str | None = None,
paths: _IntoStrArray = None,
) -> None: ...
def checkout_index(
self,
index: Index | None = None,
*,
callbacks: CheckoutCallbacks | None = None,
strategy: CheckoutStrategy | None = None,
directory: str | None = None,
paths: _IntoStrArray = None,
) -> None: ...
def checkout_tree(
self,
treeish: Object,
*,
callbacks: CheckoutCallbacks | None = None,
strategy: CheckoutStrategy | None = None,
directory: str | None = None,
paths: _IntoStrArray = None,
) -> None: ...
def checkout(
self,
refname: str | Reference | None = None,
*,
callbacks: CheckoutCallbacks | None = None,
strategy: CheckoutStrategy | None = None,
directory: str | None = None,
paths: _IntoStrArray = None,
) -> None: ...
def set_head(self, target: _OidArg) -> None: ...
def diff(
self,
a: bytes | str | Oid | Blob | Tree | None = None,
b: bytes | str | Oid | Blob | Tree | None = None,
cached: bool = False,
flags: DiffOption = ...,
context_lines: int = 3,
interhunk_lines: int = 0,
) -> Diff: ...
def state(self) -> RepositoryState: ...
def state_cleanup(self) -> None: ...
def blame(
self,
path: StrOrBytesPath,
flags: BlameFlag = ...,
min_match_characters: int | None = None,
newest_commit: _OidArg | None = None,
oldest_commit: _OidArg | None = None,
min_line: int | None = None,
max_line: int | None = None,
) -> Blame: ...
@property
def index(self) -> Index: ...
def merge_file_from_index(self, ancestor: IndexEntry | None, ours: IndexEntry | None, theirs: IndexEntry | None) -> str: ...
def merge_commits(
self,
ours: str | Oid | Commit,
theirs: str | Oid | Commit,
favor: MergeFavor = ...,
flags: MergeFlag = ...,
file_flags: MergeFileFlag = ...,
) -> Index: ...
def merge_trees(
self,
ancestor: str | Oid | Tree,
ours: str | Oid | Tree,
theirs: str | Oid | Tree,
favor: MergeFavor = ...,
flags: MergeFlag = ...,
file_flags: MergeFileFlag = ...,
) -> Index: ...
def merge(self, id: Oid | str, favor: MergeFavor = ..., flags: MergeFlag = ..., file_flags: MergeFileFlag = ...) -> None: ...
@property
def raw_message(self) -> bytes: ...
@property
def message(self) -> str: ...
def remove_message(self) -> None: ...
def describe(
self,
committish: str | Reference | Commit | None = None,
max_candidates_tags: int | None = None,
describe_strategy: DescribeStrategy = ...,
pattern: str | None = None,
only_follow_first_parent: bool | None = None,
show_commit_oid_as_fallback: bool | None = None,
abbreviated_size: int | None = None,
always_use_long_format: bool | None = None,
dirty_suffix: str | None = None,
) -> str: ...
def stash(
self,
stasher: Signature,
message: str | None = None,
keep_index: bool = False,
include_untracked: bool = False,
include_ignored: bool = False,
keep_all: bool = False,
paths: list[str] | None = None,
) -> Oid: ...
def stash_apply(
self,
index: int = 0,
*,
callbacks: StashApplyCallbacks | None = None,
reinstate_index: bool = False,
strategy: CheckoutStrategy | None = None,
directory: str | None = None,
paths: _IntoStrArray = None,
) -> None: ...
def stash_drop(self, index: int = 0) -> None: ...
def stash_pop(
self,
index: int = 0,
*,
callbacks: StashApplyCallbacks | None = None,
reinstate_index: bool = False,
strategy: CheckoutStrategy | None = None,
directory: str | None = None,
paths: _IntoStrArray = None,
) -> None: ...
def write_archive(
self, treeish: _OidArg | Tree, archive: _SupportsAddfile, timestamp: int | None = None, prefix: str = ""
) -> None: ...
def ahead_behind(self, local: _OidArg, upstream: _OidArg) -> tuple[int, int]: ...
def get_attr(
self, path: StrOrBytesPath, name: str | bytes, flags: AttrCheck = ..., commit: Oid | str | None = None
) -> bool | None | str: ...
@property
def ident(self) -> tuple[str, str]: ...
def set_ident(self, name: bytes | str | None, email: bytes | str | None) -> None: ...
def revert_commit(self, revert_commit: Commit, our_commit: Commit, mainline: int = 0) -> Index: ...
def amend_commit(
self,
commit: Commit | _OidArg,
refname: Reference | str | None,
author: Signature | None = None,
committer: Signature | None = None,
message: bytes | str | None = None,
tree: Tree | _OidArg | None = None,
encoding: str = "UTF-8",
) -> Oid: ...
class Repository(BaseRepository):
def __init__(self, path: str | None = None, flags: RepositoryOpenFlag = ...) -> None: ...

View File

@@ -0,0 +1,37 @@
import pygit2.enums
class SearchPathList:
def __getitem__(self, key: int) -> str: ...
def __setitem__(self, key: int, value: bytes | str) -> None: ...
class Settings:
def __init__(self) -> None: ...
@property
def search_path(self) -> SearchPathList: ...
@property
def mwindow_size(self) -> int: ...
@mwindow_size.setter
def mwindow_size(self, value: int) -> None: ...
@property
def mwindow_mapped_limit(self) -> int: ...
@mwindow_mapped_limit.setter
def mwindow_mapped_limit(self, value: int) -> None: ...
@property
def cached_memory(self) -> tuple[int, int]: ...
def enable_caching(self, value: bool = True) -> None: ...
def disable_pack_keep_file_checks(self, value: bool = True) -> None: ...
def cache_max_size(self, value: int) -> None: ...
def cache_object_limit(self, object_type: pygit2.enums.ObjectType, value: int) -> None: ...
@property
def ssl_cert_file(self) -> bytes | str: ...
@ssl_cert_file.setter
def ssl_cert_file(self, value: bytes | str) -> None: ...
@ssl_cert_file.deleter
def ssl_cert_file(self) -> None: ...
@property
def ssl_cert_dir(self) -> bytes | str: ...
@ssl_cert_dir.setter
def ssl_cert_dir(self, value: bytes | str) -> None: ...
@ssl_cert_dir.deleter
def ssl_cert_dir(self) -> None: ...
def set_ssl_cert_locations(self, cert_file: bytes | str, cert_dir: bytes | str) -> None: ...

View File

@@ -0,0 +1,38 @@
from collections.abc import Iterable, Iterator
from ._pygit2 import Oid
from .callbacks import RemoteCallbacks
from .enums import SubmoduleIgnore, SubmoduleStatus
from .repository import BaseRepository, Repository
class Submodule:
def __del__(self) -> None: ...
def open(self) -> Repository: ...
def init(self, overwrite: bool = False) -> None: ...
def update(self, init: bool = False, callbacks: RemoteCallbacks | None = None) -> None: ...
def reload(self, force: bool = False) -> None: ...
@property
def name(self) -> str: ...
@property
def path(self) -> str: ...
@property
def url(self) -> str: ...
@property
def branch(self) -> str: ...
@property
def head_id(self) -> Oid: ...
class SubmoduleCollection:
def __init__(self, repository: BaseRepository) -> None: ...
def __getitem__(self, name: str) -> Submodule: ...
def __contains__(self, name: str) -> bool: ...
def __iter__(self) -> Iterator[Submodule]: ...
def get(self, name: str) -> Submodule | None: ...
def add(self, url: str, path: str, link: bool = True, callbacks: RemoteCallbacks | None = None) -> Submodule: ...
def init(self, submodules: Iterable[str] | None = None, overwrite: bool = False) -> None: ...
def update(
self, submodules: Iterable[str] | None = None, init: bool = False, callbacks: RemoteCallbacks | None = None
) -> None: ...
def status(self, name: str, ignore: SubmoduleIgnore = ...) -> SubmoduleStatus: ...
def cache_all(self) -> None: ...
def cache_clear(self) -> None: ...

View File

@@ -0,0 +1,43 @@
import types
from _typeshed import StrOrBytesPath, StrPath
from typing import Generic, TypeVar
from typing_extensions import TypeAlias
from _cffi_backend import _CDataBase
def maybe_string(ptr: _CDataBase) -> str | None: ...
def to_bytes(s: _CDataBase | StrOrBytesPath | None, encoding: str = "utf-8", errors: str = "strict") -> _CDataBase | bytes: ...
def to_str(s: StrOrBytesPath) -> str: ...
def ptr_to_bytes(ptr_cdata: _CDataBase) -> bytes: ...
def strarray_to_strings(arr: _GitStrArray) -> list[str]: ...
# Actual type: _cffi_backend.__CDataOwn <cdata 'struct git_strarray *'>
# This is not a real subclassing. Just ensuring type-checkers sees this type as compatible with _CDataBase
# pyright has no error code for subclassing final
class _GitStrArray(_CDataBase): # type: ignore[misc] # pyright: ignore
count: int
strings: _CDataBase # <cdata 'char * *'>
_IntoStrArray: TypeAlias = list[StrPath] | tuple[StrPath] | None
class StrArray:
array: _CDataBase | _GitStrArray
def __init__(self, l: _IntoStrArray) -> None: ...
def __enter__(self) -> _CDataBase: ...
def __exit__(
self, type: type[BaseException] | None, value: BaseException | None, traceback: types.TracebackType | None
) -> None: ...
_T = TypeVar("_T")
class _GenericContainer(Generic[_T]):
def __len__(self) -> int: ...
def __getitem__(self, idx: int) -> _T: ...
class GenericIterator(Generic[_T]):
container: _GenericContainer[_T]
length: int
idx: int
def __init__(self, container: _GenericContainer[_T]) -> None: ...
def next(self) -> _T: ...
def __next__(self) -> _T: ...