ベアリポジトリでGitPythonを使用しており、SHAで特定のgitオブジェクトを取得しようとしています。gitを直接使用した場合、これを行うだけです
git ls-tree sha_of_tree
git show sha_of_blob
私は GitPython を使用していて、特定のツリーを取得したいので、次のようにします。
repo = Repo("path_to_my_repo")
repo.tree("b466a6098a0287ac568ef0ad783ae2c35d86362b")
そしてこれを取り戻す
<git.Tree "b466a6098a0287ac568ef0ad783ae2c35d86362b">
ツリー オブジェクトができましたが、パス、名前、ブロブなどの属性にアクセスできません。
repo.tree("b466a6098a0287ac568ef0ad783ae2c35d86362b").path
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Python27\lib\site-packages\gitdb\util.py", line 238, in __getattr__
self._set_cache_(attr)
File "c:\Python27\lib\site-packages\git\objects\tree.py", line 147, in _set_cache_
super(Tree, self)._set_cache_(attr)
File "c:\Python27\lib\site-packages\git\objects\base.py", line 157, in _set_cache_
raise AttributeError( "path and mode attributes must have been set during %s object creation" % type(self).__name__ )
AttributeError: path and mode attributes must have been set during Tree object creation
しかし、次のように入力すると機能します
repo.tree().trees[0].path
私の質問の他の部分は、GitPython で blob オブジェクトを取得する方法です。唯一のオブジェクト ツリーに属性 blob があることに気付きました。そのため、SHA によって blob を取得するには、(a) まずそれが属するツリーを知り、(b) この blob を見つけ、(c)data_stream
メソッドを呼び出す必要があります。私はちょうどすることができました
repo.git.execute("git show blob_sha")
しかし、これがこれを行う唯一の方法であることを最初に知りたいと思います。