Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_commit(data, marker=b'Default', blob=None):
if not blob:
blob = Blob.from_string(b'The blob content ' + marker)
tree = Tree()
tree.add(b"thefile_" + marker, 0o100644, blob.id)
cmt = Commit()
if data:
assert isinstance(data[-1], Commit)
cmt.parents = [data[-1].id]
cmt.tree = tree.id
author = b"John Doe " + marker + b" "
cmt.author = cmt.committer = author
tz = parse_timezone(b'-0200')[0]
cmt.commit_time = cmt.author_time = int(time())
cmt.commit_timezone = cmt.author_timezone = tz
cmt.encoding = b"UTF-8"
cmt.message = b"The commit message " + marker
tag = Tag()
tag.tagger = b"john@doe.net"
tag.message = b"Annotated tag"
def create_commit(data, marker=b'Default', blob=None):
if not blob:
blob = Blob.from_string(b'The blob content ' + marker)
tree = Tree()
tree.add(b"thefile_" + marker, 0o100644, blob.id)
cmt = Commit()
if data:
assert isinstance(data[-1], Commit)
cmt.parents = [data[-1].id]
cmt.tree = tree.id
author = b"John Doe " + marker + b" "
cmt.author = cmt.committer = author
tz = parse_timezone(b'-0200')[0]
cmt.commit_time = cmt.author_time = int(time())
cmt.commit_timezone = cmt.author_timezone = tz
cmt.encoding = b"UTF-8"
cmt.message = b"The commit message " + marker
tag = Tag()
tag.tagger = b"john@doe.net"
def test_add_thin_pack_ext_ref(self):
sos = swift.SwiftObjectStore(self.fsc)
odata = self._put_pack(sos, 1, 'Default1')
ref_blob_content = odata[0].as_raw_string()
ref_blob_id = odata[0].id
new_blob = Blob.from_string(ref_blob_content.replace('blob',
'yummy blob'))
blob, tree, tag, cmt = \
create_commit([], marker='Default2', blob=new_blob)
data = [(REF_DELTA, (ref_blob_id, blob.as_raw_string())),
(tree.type_num, tree.as_raw_string()),
(cmt.type_num, cmt.as_raw_string()),
(tag.type_num, tag.as_raw_string())]
f = BytesIO()
build_pack(f, data, store=sos)
sos.add_thin_pack(f.read, None)
self.assertEqual(len(self.fsc.store), 6)
def step_impl_given(context):
context.test_git_repo_dir = tempfile.mkdtemp("paasta_tools_deployments_json_itest")
context.test_git_repo = Repo.init(context.test_git_repo_dir)
paasta_print("Temp repo in %s" % context.test_git_repo_dir)
blob = Blob.from_string(b"My file content\n")
tree = Tree()
tree.add(b"spam", 0o0100644, blob.id)
commit = Commit()
commit.author = commit.committer = b"itest author"
commit.commit_time = commit.author_time = int(time())
commit.commit_timezone = commit.author_timezone = parse_timezone(b"-0200")[0]
commit.message = b"Initial commit"
commit.tree = tree.id
object_store = context.test_git_repo.object_store
object_store.add_object(blob)
object_store.add_object(tree)
object_store.add_object(commit)
context.test_git_repo.refs[b"refs/heads/master"] = commit.id
context.expected_commit_as_bytes = commit.id
context.expected_commit = context.expected_commit_as_bytes.decode()
def create_commit(data, marker=b'Default', blob=None):
if not blob:
blob = Blob.from_string(b'The blob content ' + marker)
tree = Tree()
tree.add(b"thefile_" + marker, 0o100644, blob.id)
cmt = Commit()
if data:
assert isinstance(data[-1], Commit)
cmt.parents = [data[-1].id]
cmt.tree = tree.id
author = b"John Doe " + marker + b" "
cmt.author = cmt.committer = author
tz = parse_timezone(b'-0200')[0]
cmt.commit_time = cmt.author_time = int(time())
cmt.commit_timezone = cmt.author_timezone = tz
cmt.encoding = b"UTF-8"
cmt.message = b"The commit message " + marker
tag = Tag()
tag.tagger = b"john@doe.net"
tag.message = b"Annotated tag"
tag.tag_timezone = parse_timezone(b'-0200')[0]
tag.tag_time = cmt.author_time
tag.object = (Commit, cmt.id)
tag.name = b"v_" + marker + b"_0.1"
def test_push_data_branch(self):
def determine_wants(*args):
return {"refs/heads/master": local_repo.refs["HEAD"]}
local_repo = repo.Repo.init(self.temp_d, mkdir=True)
os.mkdir(os.path.join(self.temp_d, "dir"))
files = ('testfile', 'testfile2', 'dir/testfile3')
i = 0
for f in files:
open(os.path.join(self.temp_d, f), 'w').write("DATA %s" % i)
i += 1
local_repo.stage(files)
local_repo.do_commit('Test commit', 'fbo@localhost',
ref='refs/heads/master')
swift.SwiftRepo.init_bare(self.scon, self.conf)
tcp_client = client.TCPGitClient(self.server_address,
port=self.port)
tcp_client.send_pack(self.fakerepo,
determine_wants,
local_repo.object_store.generate_pack_data)
swift_repo = swift.SwiftRepo("fakerepo", self.conf)
def test_push_multiple_branch(self):
def determine_wants(*args):
return {"refs/heads/mybranch":
local_repo.refs["refs/heads/mybranch"],
"refs/heads/master":
local_repo.refs["refs/heads/master"],
"refs/heads/pullr-108":
local_repo.refs["refs/heads/pullr-108"]}
local_repo = repo.Repo.init(self.temp_d, mkdir=True)
# Nothing in the staging area
local_shas = {}
remote_shas = {}
for branch in ('master', 'mybranch', 'pullr-108'):
local_shas[branch] = local_repo.do_commit(
'Test commit %s' % branch, 'fbo@localhost',
ref='refs/heads/%s' % branch)
swift.SwiftRepo.init_bare(self.scon, self.conf)
tcp_client = client.TCPGitClient(self.server_address,
port=self.port)
tcp_client.send_pack(self.fakerepo,
determine_wants,
local_repo.object_store.generate_pack_data)
swift_repo = swift.SwiftRepo("fakerepo", self.conf)
for branch in ('master', 'mybranch', 'pullr-108'):
remote_shas[branch] = swift_repo.refs.read_loose_ref(
def test_clone_bare(self):
local_repo = repo.Repo.init(self.temp_d, mkdir=True)
swift.SwiftRepo.init_bare(self.scon, self.conf)
tcp_client = client.TCPGitClient(self.server_address,
port=self.port)
remote_refs = tcp_client.fetch(self.fakerepo, local_repo)
# The remote repo is empty (no refs retreived)
self.assertEqual(remote_refs, None)
def step_impl_given(context):
context.test_git_repo_dir = tempfile.mkdtemp("paasta_tools_deployments_json_itest")
context.test_git_repo = Repo.init(context.test_git_repo_dir)
paasta_print("Temp repo in %s" % context.test_git_repo_dir)
blob = Blob.from_string(b"My file content\n")
tree = Tree()
tree.add(b"spam", 0o0100644, blob.id)
commit = Commit()
commit.author = commit.committer = b"itest author"
commit.commit_time = commit.author_time = int(time())
commit.commit_timezone = commit.author_timezone = parse_timezone(b"-0200")[0]
commit.message = b"Initial commit"
commit.tree = tree.id
object_store = context.test_git_repo.object_store
object_store.add_object(blob)
object_store.add_object(tree)
for f in files:
open(os.path.join(self.temp_d, f), 'w').write("DATA %s" % i)
i += 1
local_repo.stage(files)
local_repo.do_commit('Test commit', 'fbo@localhost',
ref='refs/heads/master')
swift.SwiftRepo.init_bare(self.scon, self.conf)
tcp_client = client.TCPGitClient(self.server_address,
port=self.port)
tcp_client.send_pack(self.fakerepo,
determine_wants,
local_repo.object_store.generate_pack_data)
swift_repo = swift.SwiftRepo("fakerepo", self.conf)
commit_sha = swift_repo.refs.read_loose_ref('refs/heads/master')
otype, data = swift_repo.object_store.get_raw(commit_sha)
commit = objects.ShaFile.from_raw_string(otype, data)
otype, data = swift_repo.object_store.get_raw(commit._tree)
tree = objects.ShaFile.from_raw_string(otype, data)
objs = tree.items()
objs_ = []
for tree_entry in objs:
objs_.append(swift_repo.object_store.get_raw(tree_entry.sha))
# Blob
self.assertEqual(objs_[1][1], 'DATA 0')
self.assertEqual(objs_[2][1], 'DATA 1')
# Tree
self.assertEqual(objs_[0][0], 2)