Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_cache_object_limit_proxy(self):
new_limit = 4 * 1024
pygit2.settings.cache_object_limit(GIT_OBJ_BLOB, new_limit)
def test_read(self):
with pytest.raises(TypeError): self.repo.read(123)
self.assertRaisesWithArg(KeyError, '1' * 40, self.repo.read, '1' * 40)
ab = self.repo.read(BLOB_OID)
a = self.repo.read(BLOB_HEX)
assert ab == a
assert (GIT_OBJ_BLOB, b'a contents\n') == a
a2 = self.repo.read('7f129fd57e31e935c6d60a0c794efe4e6927664b')
assert (GIT_OBJ_BLOB, b'a contents 2\n') == a2
a_hex_prefix = BLOB_HEX[:4]
a3 = self.repo.read(a_hex_prefix)
assert (GIT_OBJ_BLOB, b'a contents\n') == a3
def test_new_tag(self):
name = 'thetag'
target = 'af431f20fc541ed6d5afede3e2dc7160f6f01f16'
message = 'Tag a blob.\n'
tagger = pygit2.Signature('John Doe', 'jdoe@example.com', 12347, 0)
target_prefix = target[:5]
too_short_prefix = target[:3]
self.assertRaises(ValueError, self.repo.create_tag, name,
too_short_prefix, pygit2.GIT_OBJ_BLOB, tagger,
message)
sha = self.repo.create_tag(name, target_prefix, pygit2.GIT_OBJ_BLOB,
tagger, message)
tag = self.repo[sha]
self.assertEqual('3ee44658fd11660e828dfc96b9b5c5f38d5b49bb', tag.hex)
self.assertEqual(name, tag.name)
self.assertEqual(target, tag.target.hex)
self.assertEqualSignature(tagger, tag.tagger)
self.assertEqual(message, tag.message)
self.assertEqual(name, self.repo[tag.hex].name)
def test_create_blob(self):
blob_oid = self.repo.create_blob(BLOB_NEW_CONTENT)
blob = self.repo[blob_oid]
self.assertTrue(isinstance(blob, pygit2.Blob))
self.assertEqual(pygit2.GIT_OBJ_BLOB, blob.type)
self.assertEqual(blob_oid, blob.oid)
self.assertEqual(
utils.gen_blob_sha1(BLOB_NEW_CONTENT),
blob_oid.hex)
self.assertEqual(BLOB_NEW_CONTENT, blob.data)
self.assertEqual(len(BLOB_NEW_CONTENT), blob.size)
self.assertEqual(BLOB_NEW_CONTENT, blob.read_raw())
def checkout_file(self, path, commit):
"""Checkouts the given path at the given commit."""
_check_path_is_repo_relative(path)
git_path = _get_git_path(path)
o = self.gl_repo.git_repo[commit.tree[git_path].id]
assert o.type != pygit2.GIT_OBJ_COMMIT
assert o.type != pygit2.GIT_OBJ_TAG
if o.type == pygit2.GIT_OBJ_BLOB:
full_path = os.path.join(self.gl_repo.root, path)
dirname = os.path.dirname(full_path)
if not os.path.exists(dirname):
try:
os.makedirs(dirname)
except OSError as exc: # guard against race condition
if exc.errno != errno.EEXIST:
raise
with io.open(full_path, mode='wb') as dst:
dst.write(o.data)
# So as to not get confused with the status of the file we also add it.
# This prevents getting into a situation in which the staged version is
# different from the working version. In such a case, the file would
# appear as modified to Gitless when it shouldn't. This is also consistent
# with the behavior of `git checkout ` that also adds the
# -*- coding: utf-8 -*-
from pygit2 import (GIT_OBJ_TAG,
GIT_OBJ_BLOB,
GIT_OBJ_TREE,
GIT_OBJ_COMMIT)
PYGIT2_OBJ_TYPE = {
GIT_OBJ_TAG: 'tag',
GIT_OBJ_BLOB: 'blob',
GIT_OBJ_TREE: 'tree',
GIT_OBJ_COMMIT: 'commit',
}
def resolve_type(repository, version):
try:
obj = repository.revparse_single(version)
type = PYGIT2_OBJ_TYPE[obj.type]
except KeyError:
type = None
except ValueError:
type = None
return type
if req_path:
req_path = _remove_slash(req_path)
try:
obj = repository.revparse_single(ref)
except (ValueError, KeyError):
raise JagareError("Reference not found.")
commit_obj = None
if obj.type == GIT_OBJ_TREE:
tree_obj = obj
elif obj.type == GIT_OBJ_TAG:
commit_obj = repository.revparse_single(obj.target.hex)
tree_obj = commit_obj.tree
elif obj.type == GIT_OBJ_BLOB:
raise JagareError("Object is blob, doesn't contain any tree")
elif obj.type == GIT_OBJ_COMMIT:
commit_obj = obj
tree_obj = obj.tree
if req_path:
tree_entry = tree_obj[req_path]
tree_obj = repository[tree_entry.id]
walker = _walk_tree(tree_obj, req_path)
else:
walker = _walk_tree(tree_obj)
ret_tree = {}
submodule_obj = None
submodule = None
try:
def create_blob(self, data):
return self.write(pygit2.GIT_OBJ_BLOB, data)
def write_blob(repository, node):
if node.type != 'blob':
return None
if node.id:
return None
if node.action == 'remove':
return None
node.id = repository.write(GIT_OBJ_BLOB, node.content)
def is_blob(self):
return self.type == GIT_OBJ_BLOB