2727
2828from typing import TYPE_CHECKING
2929
30- from ._pygit2 import Commit , Oid
30+ from ._pygit2 import Branch , Commit , Oid , Reference
3131from .enums import BranchType , ReferenceType
3232
3333# Need BaseRepository for type hints, but don't let it cause a circular dependency
3737
3838class Branches :
3939 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 ,
4144 ):
4245 self ._repository = repository
4346 self ._flag = flag
@@ -76,13 +79,13 @@ def __iter__(self):
7679 if self ._commit is None or self .get (branch_name ) is not None :
7780 yield branch_name
7881
79- def create (self , name : str , commit , force = False ):
82+ def create (self , name : str , commit : Commit , force : bool = False ):
8083 return self ._repository .create_branch (name , commit , force )
8184
8285 def delete (self , name : str ):
8386 self [name ].delete ()
8487
85- def _valid (self , branch ):
88+ def _valid (self , branch : Branch | Reference ):
8689 if branch .type == ReferenceType .SYMBOLIC :
8790 branch = branch .resolve ()
8891
@@ -92,9 +95,9 @@ def _valid(self, branch):
9295 or self ._repository .descendant_of (branch .target , self ._commit )
9396 )
9497
95- def with_commit (self , commit ):
98+ def with_commit (self , commit : Commit | Oid | str | None ):
9699 assert self ._commit is None
97100 return Branches (self ._repository , self ._flag , commit )
98101
99- def __contains__ (self , name ):
102+ def __contains__ (self , name : str ):
100103 return self .get (name ) is not None
0 commit comments