GitPython0.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
このデコレータは、パス参照を正しく解決できるように、リポジトリにchdirしようとします。ただし、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.