Skip to content

Commit 4dd179d

Browse files
committed
improve types according to test/test_repository.py
1 parent 876b755 commit 4dd179d

File tree

4 files changed

+183
-90
lines changed

4 files changed

+183
-90
lines changed

pygit2/_pygit2.pyi

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ from typing import (
1717
overload,
1818
)
1919

20-
from . import Index
20+
from . import Index, IndexEntry
2121
from ._libgit2.ffi import (
2222
GitCommitC,
2323
GitMergeOptionsC,
@@ -28,7 +28,7 @@ from ._libgit2.ffi import (
2828
_Pointer,
2929
)
3030
from .blame import Blame
31-
from .callbacks import CheckoutCallbacks
31+
from .callbacks import CheckoutCallbacks, StashApplyCallbacks
3232
from .config import Config
3333
from .enums import (
3434
ApplyLocation,
@@ -59,6 +59,7 @@ from .enums import (
5959
SortMode,
6060
)
6161
from .filter import Filter
62+
from .index import MergeFileResult
6263
from .packbuilder import PackBuilder
6364
from .remotes import Remote
6465
from .repository import BaseRepository
@@ -765,7 +766,9 @@ class Repository:
765766
def _from_c(cls, ptr: 'GitRepositoryC', owned: bool) -> 'Repository': ...
766767
def __iter__(self) -> Iterator[Oid]: ...
767768
def __getitem__(self, key: str | Oid) -> Object: ...
768-
def add_worktree(self, name: str, path: str, ref: Reference = ...) -> Worktree: ...
769+
def add_worktree(
770+
self, name: str, path: str | Path, ref: Reference = ...
771+
) -> Worktree: ...
769772
def amend_commit(
770773
self,
771774
commit: Commit | Oid | str,
@@ -797,13 +800,14 @@ class Repository:
797800
) -> Blame: ...
798801
def checkout(
799802
self,
800-
refname: Optional[_OidArg],
803+
refname: _OidArg | None | Reference = None,
801804
*,
802805
strategy: CheckoutStrategy | None = None,
803-
directory: str | None = None,
806+
directory: str | Path | None = None,
804807
paths: list[str] | None = None,
805808
callbacks: CheckoutCallbacks | None = None,
806809
) -> None: ...
810+
def ahead_behind(self, local: _OidArg, upstream: _OidArg) -> tuple[int, int]: ...
807811
def cherrypick(self, id: _OidArg) -> None: ...
808812
def compress_references(self) -> None: ...
809813
@property
@@ -893,6 +897,12 @@ class Repository:
893897
commit: _OidArg | None = None,
894898
) -> bool | None | str: ...
895899
def git_object_lookup_prefix(self, oid: _OidArg) -> Object: ...
900+
def hashfile(
901+
self,
902+
path: str,
903+
object_type: ObjectType = ObjectType.BLOB,
904+
as_path: str | None = None,
905+
) -> Oid: ...
896906
def list_worktrees(self) -> list[str]: ...
897907
def listall_branches(self, flag: BranchType = BranchType.LOCAL) -> list[str]: ...
898908
def listall_mergeheads(self) -> list[Oid]: ...
@@ -930,6 +940,13 @@ class Repository:
930940
flags: MergeFlag = MergeFlag.FIND_RENAMES,
931941
file_flags: MergeFileFlag = MergeFileFlag.DEFAULT,
932942
) -> Index: ...
943+
def merge_file_from_index(
944+
self,
945+
ancestor: IndexEntry | None,
946+
ours: IndexEntry | None,
947+
theirs: IndexEntry | None,
948+
use_deprecated: bool = True,
949+
) -> str | MergeFileResult | None: ...
933950
@staticmethod
934951
def _merge_options(
935952
favor: int | MergeFavor, flags: int | MergeFlag, file_flags: int | MergeFileFlag
@@ -971,12 +988,45 @@ class Repository:
971988
def revparse(self, revspec: str) -> RevSpec: ...
972989
def revparse_ext(self, revision: str) -> tuple[Object, Reference]: ...
973990
def revparse_single(self, revision: str) -> Object: ...
991+
def revert(self, commit: Commit) -> None: ...
992+
def revert_commit(
993+
self, revert_commit: Commit, our_commit: Commit, mainline: int = 0
994+
) -> Index: ...
974995
def set_ident(self, name: str, email: str) -> None: ...
975996
def set_odb(self, odb: Odb) -> None: ...
976997
def set_refdb(self, refdb: Refdb) -> None: ...
977998
def status(
978999
self, untracked_files: str = 'all', ignored: bool = False
9791000
) -> dict[str, int]: ...
1001+
def stash(
1002+
self,
1003+
stasher: Signature,
1004+
message: str | None = None,
1005+
keep_index: bool = False,
1006+
include_untracked: bool = False,
1007+
include_ignored: bool = False,
1008+
keep_all: bool = False,
1009+
paths: list[str] | None = None,
1010+
) -> None: ...
1011+
def stash_apply(
1012+
self,
1013+
index: int = 0,
1014+
reinstate_index: bool | None = None,
1015+
include_untracked: bool | None = None,
1016+
message: str | None = None,
1017+
strategy: CheckoutStrategy | None = None,
1018+
callbacks: StashApplyCallbacks | None = None,
1019+
) -> None: ...
1020+
def stash_pop(
1021+
self,
1022+
index: int = 0,
1023+
reinstate_index: bool | None = None,
1024+
include_untracked: bool | None = None,
1025+
message: str | None = None,
1026+
strategy: CheckoutStrategy | None = None,
1027+
callbacks: StashApplyCallbacks | None = None,
1028+
) -> None: ...
1029+
def stash_drop(self, index: int = 0) -> None: ...
9801030
def status_file(self, path: str) -> int: ...
9811031
def state(self) -> RepositoryState: ...
9821032
def state_cleanup(self) -> None: ...

pygit2/index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __contains__(self, path) -> bool:
8383
check_error(err)
8484
return True
8585

86-
def __getitem__(self, key):
86+
def __getitem__(self, key: str | int | PathLike[str]) -> 'IndexEntry':
8787
centry = ffi.NULL
8888
if isinstance(key, str) or hasattr(key, '__fspath__'):
8989
centry = C.git_index_get_bypath(self._index, to_bytes(key), 0)
@@ -389,7 +389,7 @@ class MergeFileResult:
389389
automergeable: bool
390390
'True if the output was automerged, false if the output contains conflict markers'
391391

392-
path: typing.Union[str, None]
392+
path: typing.Union[str, None, PathLike[str]]
393393
'The path that the resultant merge file should use, or None if a filename conflict would occur'
394394

395395
mode: FileMode

test/test_index.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def test_read(testrepo: Repository) -> None:
4949
assert len(index) == 2
5050

5151
with pytest.raises(TypeError):
52-
index[()]
53-
utils.assertRaisesWithArg(ValueError, -4, lambda: index[-4])
52+
index[()] # type: ignore
53+
utils.assertRaisesWithArg(ValueError, -4, lambda: index[-4]) # type: ignore
5454
utils.assertRaisesWithArg(KeyError, 'abc', lambda: index['abc'])
5555

5656
sha = 'a520c24d85fbfc815d385957eed41406ca5a860b'

0 commit comments

Comments
 (0)