Skip to content

Commit 4114365

Browse files
committed
Messing around with pygit2
TODO: Add "scrap add" to take a scrap, serialize it, and commit it to a scrapyard.
1 parent ebe5b79 commit 4114365

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

git.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pathlib
2+
3+
import pygit2
4+
5+
6+
yard = "/tmp/scrapyard"
7+
repo = pygit2.init_repository(yard, bare=True)
8+
9+
root = repo.TreeBuilder()
10+
obj_id = repo.create_blob(b"hello world from pygit2!")
11+
root.insert("test", obj_id, pygit2.GIT_FILEMODE_BLOB)
12+
tree_id = root.write()
13+
14+
ref = "HEAD"
15+
author = pygit2.Signature("Alice Author", "[email protected]")
16+
message = "Initial commit"
17+
parents: object = []
18+
repo.create_commit(ref, author, author, message, tree_id, parents)
19+
20+
root = repo.TreeBuilder()
21+
obj_id = repo.create_blob(b"goodbye world from pygit2!")
22+
other_obj_id = repo.create_blob(b"hello chris")
23+
root.insert("test", obj_id, pygit2.GIT_FILEMODE_BLOB)
24+
root.insert("another_one", other_obj_id, pygit2.GIT_FILEMODE_BLOB)
25+
tree_id = root.write()
26+
27+
ref = repo.head.name
28+
author = pygit2.Signature("Alice Author", "[email protected]")
29+
message = "Second commit"
30+
parents = [repo.head.target]
31+
repo.create_commit(ref, author, author, message, tree_id, parents)

0 commit comments

Comments
 (0)