@@ -705,7 +705,7 @@ def __init__(self, global_options: types.GlobalOptions, repo_path: str) -> None:
705
705
# Disable ownership sanity checks to maintain compatibility with
706
706
# behavior of libgit2 1.4.2 and earlier; later versions (i.e. with
707
707
# pygit2 1.9.2 and later) fail in docker context otherwise.
708
- pygit2 .option (pygit2 .GIT_OPT_SET_OWNER_VALIDATION , 0 )
708
+ pygit2 .option (pygit2 .GIT_OPT_SET_OWNER_VALIDATION , 0 ) # type: ignore[attr-defined]
709
709
710
710
# Load any configuration file in the target repository. This comes
711
711
# *BEFORE* load_repo() because that method may rely on configuration data
@@ -735,13 +735,13 @@ def _iter_diff_index(
735
735
file_path = (
736
736
delta .new_file .path if delta .new_file .path else delta .old_file .path
737
737
)
738
- if delta .status == pygit2 .GIT_DELTA_DELETED :
738
+ if delta .status == pygit2 .GIT_DELTA_DELETED : # type: ignore[attr-defined]
739
739
self .logger .debug ("Skipping as the file was a git delete operation" )
740
740
continue
741
741
if delta .is_binary :
742
742
self .logger .debug ("Binary file skipped: %s" , file_path )
743
743
continue
744
- printable_diff : str = patch .text
744
+ printable_diff : str = patch .text or ""
745
745
if not self .global_options .scan_filenames :
746
746
# The `printable_diff` contains diff header,
747
747
# so we need to strip that before analyzing it
@@ -773,7 +773,7 @@ def filter_submodules(self, repo: pygit2.Repository) -> None:
773
773
self .logger .info ("Excluding submodules paths from scan." )
774
774
try :
775
775
for module in repo .listall_submodules ():
776
- submodule = repo .lookup_submodule (module )
776
+ submodule = repo .lookup_submodule (module ) # type: ignore[attr-defined]
777
777
patterns .append (re .compile (f"^{ submodule .path } " ))
778
778
except AttributeError as exc :
779
779
raise TartufoException (
@@ -825,11 +825,14 @@ def load_repo(self, repo_path: str) -> pygit2.Repository:
825
825
raise types .GitLocalException (str (exc )) from exc
826
826
827
827
def _get_chunks (
828
- self , commits : Iterable , already_searched : Set [bytes ], branch_name : str
828
+ self ,
829
+ commits : Iterable [pygit2 .Commit ],
830
+ already_searched : Set [bytes ],
831
+ branch_name : str ,
829
832
) -> Generator [types .Chunk , None , None ]:
830
833
diff_hash : bytes
831
- curr_commit : pygit2 .Commit = None
832
- prev_commit : pygit2 .Commit = None
834
+ curr_commit : Optional [ pygit2 .Commit ] = None
835
+ prev_commit : Optional [ pygit2 .Commit ] = None
833
836
for curr_commit in commits :
834
837
try :
835
838
prev_commit = curr_commit .parents [0 ]
@@ -847,7 +850,7 @@ def _get_chunks(
847
850
).digest ()
848
851
if diff_hash in already_searched :
849
852
continue
850
- diff : pygit2 .Diff = self ._repo .diff (prev_commit , curr_commit )
853
+ diff : pygit2 .Diff = self ._repo .diff (prev_commit , curr_commit ) # type: ignore[attr-defined]
851
854
already_searched .add (diff_hash )
852
855
diff .find_similar ()
853
856
for blob , file_path in self ._iter_diff_index (diff ):
@@ -860,7 +863,7 @@ def _get_chunks(
860
863
861
864
# Finally, yield the first commit to the branch
862
865
if curr_commit :
863
- tree : pygit2 .Tree = self ._repo .revparse_single (str (curr_commit .id )).tree
866
+ tree : pygit2 .Tree = self ._repo .revparse_single (str (curr_commit .id )).tree # type: ignore[attr-defined]
864
867
tree_diff : pygit2 .Diff = tree .diff_to_tree (swap = True )
865
868
iter_diff = self ._iter_diff_index (tree_diff )
866
869
for blob , file_path in iter_diff :
@@ -882,7 +885,7 @@ def chunks(self) -> Generator[types.Chunk, None, None]:
882
885
try :
883
886
if self .git_options .branch :
884
887
# Single branch only
885
- branch = self ._repo .branches .get (self .git_options .branch )
888
+ branch = self ._repo .branches .get (self .git_options .branch ) # type: ignore[attr-defined]
886
889
if not branch :
887
890
raise BranchNotFoundException (
888
891
f"Branch { self .git_options .branch } was not found."
@@ -899,7 +902,7 @@ def chunks(self) -> Generator[types.Chunk, None, None]:
899
902
# scan not only the locally checked out branches (as provided
900
903
# by self._repo.listall_branches()), but to also scan all
901
904
# available remote refs
902
- branches = list (self ._repo .branches )
905
+ branches = list (self ._repo .branches ) # type: ignore[attr-defined]
903
906
except pygit2 .GitError as exc :
904
907
raise types .GitRemoteException (str (exc )) from exc
905
908
@@ -911,13 +914,15 @@ def chunks(self) -> Generator[types.Chunk, None, None]:
911
914
branch_len = len (branches )
912
915
for branch_name in branches :
913
916
self .logger .info ("Scanning branch: %s" , branch_name )
917
+ commits : Iterable [pygit2 .Commit ]
914
918
if branch_name == "HEAD" :
915
- commits = [self ._repo .get (self ._repo .head .target )]
919
+ commits = [self ._repo .get (self ._repo .head .target )] # type: ignore[attr-defined]
916
920
else :
917
- branch = self ._repo .branches .get (branch_name )
921
+ branch = self ._repo .branches .get (branch_name ) # type: ignore[attr-defined]
918
922
try :
919
923
commits = self ._repo .walk (
920
- branch .resolve ().target , pygit2 .GIT_SORT_TOPOLOGICAL
924
+ branch .resolve ().target ,
925
+ pygit2 .GIT_SORT_TOPOLOGICAL , # type: ignore[attr-defined]
921
926
)
922
927
923
928
except AttributeError :
0 commit comments