LoginSignup
2
2

More than 5 years have passed since last update.

pygit2 でコミットする

Posted at

pygit2 のドキュメントがかなり足りないのでメモ。
(わからないことがあったら libgit2 のヘッダのドキュメントが参考になります。)

>>> import pygit2
>>> repo = pygit2.Repository('.')
>>> blob_id = repo.create_blob('hogehoge')
>>> builder = repo.TreeBuilder(repo.head.tree)
>>> builder.insert('hoge.txt', blob_id, pygit2.GIT_FILEMODE_BLOB)
>>> newtree = builder.write()
>>> author = pygit2.Signature('methane', 'inada-n [at] klab.com')
>>> repo.create_commit('HEAD', author, author, 'add hogehoge',
                       newtree, [repo.head.oid])
'\xbc&C\x96\xfb\x84\xc4\x1f\x8a\xbd\xc5h6\x98\x08i\x84\xd4\nf'
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2