34 lines
1009 B
Python
Executable File
34 lines
1009 B
Python
Executable File
#!/usr/bin/python3
|
|
""" Make sure that libgit2-glib works correctly
|
|
"""
|
|
import gi
|
|
gi.require_version("Ggit", "1.0")
|
|
from gi.repository import Ggit as Git
|
|
from gi.repository import Gio
|
|
|
|
import os
|
|
import tempfile
|
|
|
|
def test_libgit2(git_path):
|
|
"""Test libgit2"""
|
|
Git.init()
|
|
repo = Git.Repository.init_repository(Gio.file_new_for_path(git_path), True)
|
|
|
|
# Make an initial empty commit
|
|
sig = Git.Signature.new_now("bdcs-api-server", "user-email")
|
|
tree_id = repo.get_index().write_tree()
|
|
tree = repo.lookup(tree_id, Git.Tree)
|
|
repo.create_commit("HEAD", sig, sig, "UTF-8", "Initial commit", tree, [])
|
|
|
|
commit_id = repo.revparse("master").get_id()
|
|
commit = repo.lookup(commit_id, Git.Commit)
|
|
message = commit.get_message()
|
|
|
|
if message != "Initial commit":
|
|
print("ERROR: Problem with Initial commit: %s" % message)
|
|
os.exit(1)
|
|
|
|
if __name__=='__main__':
|
|
with tempfile.TemporaryDirectory(prefix="test.libgit2.") as git_repo:
|
|
test_libgit2(git_repo)
|