Created
September 19, 2012 15:21
-
-
Save pierremarc/3750225 to your computer and use it in GitHub Desktop.
Add files to a repo with pygit2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
test commit creation with pygit2 | |
To see the result: | |
rm -rf foo && python test_cc.py && cd foo/ && git log --graph --oneline --date-order --decorate --color --all && git status && cd .. | |
""" | |
import os | |
import sys | |
import pygit2 | |
import stat | |
from time import time | |
data = 'This is an empty README file' | |
fn = 'README' | |
s = pygit2.Signature('Alice Author', '[email protected]', time(), 0) | |
r = pygit2.init_repository('foo', False) | |
bld = r.TreeBuilder() | |
t = bld.write() | |
c = r.create_commit('HEAD', s,s, 'Create master branch', t, []) | |
f = open(os.path.join(r.workdir,fn), 'w') | |
f.write(data) | |
f.close() | |
b = r.create_blob_fromfile(fn) | |
bld = r.TreeBuilder(r.head.tree) | |
bld.insert(fn, b, os.stat(fn).st_mode ) | |
t = bld.write() | |
r.index.read() | |
r.index.add(fn) | |
r.index.write() | |
c = r.create_commit('HEAD', s,s, 'Added a README', t, [r.head.oid]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PyGit2 API has changed a lot. This patch works for me:
I'm not sure what's the effect of dismiss the arguments for
TreeBuilder()