27
27
28
28
from typing import TYPE_CHECKING
29
29
30
- from ._pygit2 import Commit , Oid
30
+ from ._pygit2 import Branch , Commit , Oid , Reference
31
31
from .enums import BranchType , ReferenceType
32
32
33
33
# Need BaseRepository for type hints, but don't let it cause a circular dependency
37
37
38
38
class Branches :
39
39
def __init__ (
40
- self , repository : BaseRepository , flag : BranchType = BranchType .ALL , commit = None
40
+ self ,
41
+ repository : BaseRepository ,
42
+ flag : BranchType = BranchType .ALL ,
43
+ commit : Commit | Oid | str | None = None ,
41
44
):
42
45
self ._repository = repository
43
46
self ._flag = flag
@@ -76,13 +79,13 @@ def __iter__(self):
76
79
if self ._commit is None or self .get (branch_name ) is not None :
77
80
yield branch_name
78
81
79
- def create (self , name : str , commit , force = False ):
82
+ def create (self , name : str , commit : Commit , force : bool = False ):
80
83
return self ._repository .create_branch (name , commit , force )
81
84
82
85
def delete (self , name : str ):
83
86
self [name ].delete ()
84
87
85
- def _valid (self , branch ):
88
+ def _valid (self , branch : Branch | Reference ):
86
89
if branch .type == ReferenceType .SYMBOLIC :
87
90
branch = branch .resolve ()
88
91
@@ -92,9 +95,9 @@ def _valid(self, branch):
92
95
or self ._repository .descendant_of (branch .target , self ._commit )
93
96
)
94
97
95
- def with_commit (self , commit ):
98
+ def with_commit (self , commit : Commit | Oid | str | None ):
96
99
assert self ._commit is None
97
100
return Branches (self ._repository , self ._flag , commit )
98
101
99
- def __contains__ (self , name ):
102
+ def __contains__ (self , name : str ):
100
103
return self .get (name ) is not None
0 commit comments