Вопрос по git – GitPython получает объект дерева и блоба по sha

7

Error: User Rate Limit Exceeded

git ls-tree sha_of_tree
git show sha_of_blob

Error: User Rate Limit Exceeded

repo = Repo("path_to_my_repo")
repo.tree("b466a6098a0287ac568ef0ad783ae2c35d86362b")

Error: User Rate Limit Exceeded

<git.Tree "b466a6098a0287ac568ef0ad783ae2c35d86362b">

Error: User Rate Limit Exceeded

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

Error: User Rate Limit Exceeded

repo.tree().trees[0].path

Error: User Rate Limit Exceededdata_streamError: User Rate Limit Exceeded

repo.git.execute("git show blob_sha")

Error: User Rate Limit Exceeded

Ваш Ответ

3   ответа
3

   def read_file_from_branch(self, repo, branch, path, charset='ascii'):
            '''
            return the contents of a file in a branch, without checking out the
            branch
            '''
            if branch in repo.heads:
                blob = (repo.heads[branch].commit.tree / path)
                if blob:
                    data = blob.data_stream.read()
                    if charset:
                        return data.decode(charset)
                    return data
            return None
Error: User Rate Limit Exceeded
1

Error: User Rate Limit Exceeded

>>> import binascii
>>> id_to_find = repo.head.commit.tree['README'].hexsha  # For example
>>> id_to_find
"aee35f14ee5515ee98d546a170be60690576db4b"
>>> git.objects.blob.Blob(repo, binascii.a2b_hex(id_to_find))
<git.Blob "aee35f14ee5515ee98d546a170be60690576db4b">

Error: User Rate Limit Exceeded

3

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

repo.tree().blobs # returns a list of blobs

Error: User Rate Limit Exceeded

repo.tree().trees # returns a list of trees

Error: User Rate Limit Exceeded

for t in repo.tree().trees:
    print t.blobs

Error: User Rate Limit Exceeded

repo.tree().blobs[0].path # gives the relative path
repo.tree().blobs[0].abspath # gives the absolute path

Error: User Rate Limit Exceeded

Похожие вопросы