我試圖讓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.
這個裝飾試圖CHDIR到回購的working_tree_dir
,使路徑引用可以解決正確。但是,working_tree_dir
對裸倉庫無效,因此產生AssertionError
。
有沒有人有一個想法,爲什麼這個裝飾器在這裏?它只是用於路徑解析,還是不可能在裸倉庫中創建索引?這是GitPython中的錯誤,還是我對Git的理解?
編輯:同樣,IndexFile.remove
功能聲稱(通過default_index
裝飾),我們是默認的索引。裸倉庫當然沒有默認索引,但它們可以根本沒有索引對象嗎?
@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.
我會說這很好。無論如何,如果您要直接在裸回購庫中發送這些斑點,則無需「更改」更改。 – anarcat 2015-03-30 19:53:22