I am using GitPython with an open repository, and I am trying to get a specific git object by its step. If I used git directly, I would just do it
git ls-tree sha_of_tree git show sha_of_blob
Since I am using GitPython and I want to get a specific tree, I am doing the following.
repo = Repo("path_to_my_repo") repo.tree("b466a6098a0287ac568ef0ad783ae2c35d86362b")
And bring it back
<git.Tree "b466a6098a0287ac568ef0ad783ae2c35d86362b">
Now I have a tree object, but I canβt access its attributes, such as path, name, drops, etc.
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
But if you print the following, then it works
repo.tree().trees[0].path
Another part of my question is how to get blob object with GitPython. I noticed that only the object tree has blobs attributes, so in order to get blob by sha, I must first find out which tree it belongs to, find this blob, and then call the data_stream method. I could just do
repo.git.execute("git show blob_sha")
but first, I would like to know that this is the only way to do this.