@@ -989,6 +989,34 @@ def test_is_ancestor(self):
989
989
for i , j in itertools .permutations ([c1 , 'ffffff' , '' ], r = 2 ):
990
990
self .assertRaises (GitCommandError , repo .is_ancestor , i , j )
991
991
992
+ def test_is_valid_object (self ):
993
+ repo = self .rorepo
994
+ commit_sha = 'f6aa8d1'
995
+ blob_sha = '1fbe3e4375'
996
+ tree_sha = '960b40fe36'
997
+ tag_sha = '42c2f60c43'
998
+
999
+ # Check for valid objects
1000
+ self .assertTrue (repo .is_valid_object (commit_sha ))
1001
+ self .assertTrue (repo .is_valid_object (blob_sha ))
1002
+ self .assertTrue (repo .is_valid_object (tree_sha ))
1003
+ self .assertTrue (repo .is_valid_object (tag_sha ))
1004
+
1005
+ # Check for valid objects of specific type
1006
+ self .assertTrue (repo .is_valid_object (commit_sha , 'commit' ))
1007
+ self .assertTrue (repo .is_valid_object (blob_sha , 'blob' ))
1008
+ self .assertTrue (repo .is_valid_object (tree_sha , 'tree' ))
1009
+ self .assertTrue (repo .is_valid_object (tag_sha , 'tag' ))
1010
+
1011
+ # Check for invalid objects
1012
+ self .assertFalse (repo .is_valid_object (b'1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a' , 'blob' ))
1013
+
1014
+ # Check for invalid objects of specific type
1015
+ self .assertFalse (repo .is_valid_object (commit_sha , 'blob' ))
1016
+ self .assertFalse (repo .is_valid_object (blob_sha , 'commit' ))
1017
+ self .assertFalse (repo .is_valid_object (tree_sha , 'commit' ))
1018
+ self .assertFalse (repo .is_valid_object (tag_sha , 'commit' ))
1019
+
992
1020
@with_rw_directory
993
1021
def test_git_work_tree_dotgit (self , rw_dir ):
994
1022
"""Check that we find .git as a worktree file and find the worktree
0 commit comments