How to add something to the index, commit it, then push the master branch to a named remote with dulwich?
How can I add something to the index, as in
git add .
then
git commit -m "me开发者_开发技巧ssage"
then
git push origin master
using dulwich?
So far I've found this http://www.samba.org/~jelmer/dulwich/apidocs/dulwich.index.Index.html but it doesn't say much, does it?
Thanks
This is not a tested answer but it is closer on the push part:
# set wants to master
def wantmaster(haves, wants):
global repo
return { "refs/heads/master": repo.refs["HEAD"] }
client, src = dulwich.client.get_transport_and_path(origin_uri)
client.send_pack(src, wantmaster, repo.object_store.generate_pack_contents)
A variation on this is working in my code.
In this case, you don't want the index but the repo (of which the index is a part). http://www.samba.org/~jelmer/dulwich/apidocs/dulwich.repo.Repo.html
Something like this should work:
>>> from dulwich.repo import Repo
>>> x = Repo('.')
>>> x.stage(['a'])
>>> x.do_commit(message="foo")
'151915d47467696d2f9d18de6f61be7168682aeb'
精彩评论