GitPython 0.3
将文件提交到存储库。大致来说,我是这样做的:
data = ...
istream = repo.odb.store(gitdb.IStream(git.Blob.type, len(data), StringIO(data)))
entry = git.BaseIndexEntry((stat.S_IFREG | 0644, istream.binsha, 0, path))
index = git.IndexFile.from_tree(repo, repo.heads['master'])
index.add([entry])
index.commit(commit_message)
对于非裸存储库,这一点与预期一样有效。请注意,我从不显式地接触文件系统,只接触Git的对象数据库。
IndexFile.add
函数用
git_working_dir
装饰师:
@git_working_dir
def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=None,
write=True):
"""Add files from the working tree, specific blobs or BaseIndexEntries
to the index.
这个装潢师想把房子租给回购人
working_tree_dir
,以便正确解析路径引用。然而,
对于空存储库无效,引发
AssertionError
有人知道这个装修工为什么在这里吗?它是仅仅用于路径解析,还是不可能在空存储库中创建索引?这是GitPython中的bug,还是我对Git的理解?
编辑:类似地
IndexFile.remove
函数断言(通过
default_index
decorator)我们是默认索引。裸存储库当然没有默认索引,但它们是否可以根本没有索引对象?
@post_clear_cache
@default_index
def remove(self, items, working_tree=False, **kwargs):
"""Remove the given items from the index and optionally from
the working tree as well.