diff options
author | Robert Westman <robert@byteflux.io> | 2021-06-05 12:15:38 +0200 |
---|---|---|
committer | Robert Westman <robert@byteflux.io> | 2021-06-05 12:15:38 +0200 |
commit | 385a8c6c1a72dc34f69c5273c1b4c1285cc1d3c5 (patch) | |
tree | 570d920c2e14fff195fca4529f17c8a598f466c5 /test/test_repo.py | |
parent | 01a96b92f7d873cbd531d142813c2be7ab88d5a5 (diff) | |
download | gitpython-385a8c6c1a72dc34f69c5273c1b4c1285cc1d3c5.tar.gz |
Adds repo.is_valid_object check
Diffstat (limited to 'test/test_repo.py')
-rw-r--r-- | test/test_repo.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/test_repo.py b/test/test_repo.py index 04102b01..8aced94d 100644 --- a/test/test_repo.py +++ b/test/test_repo.py @@ -989,6 +989,34 @@ class TestRepo(TestBase): for i, j in itertools.permutations([c1, 'ffffff', ''], r=2): self.assertRaises(GitCommandError, repo.is_ancestor, i, j) + def test_is_valid_object(self): + repo = self.rorepo + commit_sha = 'f6aa8d1' + blob_sha = '1fbe3e4375' + tree_sha = '960b40fe36' + tag_sha = '42c2f60c43' + + # Check for valid objects + self.assertTrue(repo.is_valid_object(commit_sha)) + self.assertTrue(repo.is_valid_object(blob_sha)) + self.assertTrue(repo.is_valid_object(tree_sha)) + self.assertTrue(repo.is_valid_object(tag_sha)) + + # Check for valid objects of specific type + self.assertTrue(repo.is_valid_object(commit_sha, 'commit')) + self.assertTrue(repo.is_valid_object(blob_sha, 'blob')) + self.assertTrue(repo.is_valid_object(tree_sha, 'tree')) + self.assertTrue(repo.is_valid_object(tag_sha, 'tag')) + + # Check for invalid objects + self.assertFalse(repo.is_valid_object(b'1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a', 'blob')) + + # Check for invalid objects of specific type + self.assertFalse(repo.is_valid_object(commit_sha, 'blob')) + self.assertFalse(repo.is_valid_object(blob_sha, 'commit')) + self.assertFalse(repo.is_valid_object(tree_sha, 'commit')) + self.assertFalse(repo.is_valid_object(tag_sha, 'commit')) + @with_rw_directory def test_git_work_tree_dotgit(self, rw_dir): """Check that we find .git as a worktree file and find the worktree |