Here is the code I use to create a new file and commit it :
# We are inside a home-made class, using GitPython
# So self.repo is a Repo() object from GitPython module
def set_content(self, path, content, commit_msg=None):
""" Add new content in ``path``. """
# Create the stream
stream = StringIO(content.encode('utf-8'))
stream.seek(0, 2)
streamlen = stream.tell()
stream.seek(0)
istream = IStream('blob', streamlen, stream)
# Add it to the repository object database
self.repo.odb.store(istream)
# Create the corresponding Blob object
blob = Blob(self.repo, istream.binsha, 0100644, path.encode('utf-8'))
# Commit
self.repo.index.add([IndexEntry.from_blob(blob)])
if not commit_msg:
commit_msg = ugettext(u'Update Wiki: {0}').format(path).encode('utf-8')
self.repo.index.commit(commit_msg)
# Update internal informations
self.parse()
It works just fine.
The problem comes when I commit in the git repository from the git command line :
- commit from
set_content()
- commit from
set_content()
- commit from command line
- new commit from
set_content()
: files committed by the previous commit are deleted.
I can't understand where is the mistake.
If someone is able to help me, thanks :)