3

How can I add something to the index, as in

git add .

then

git commit -m "message"

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

Flavius
  • 13,566
  • 13
  • 80
  • 126

2 Answers2

5

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.

dmedvinsky
  • 8,046
  • 3
  • 31
  • 25
3

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'
jelmer
  • 2,405
  • 14
  • 27