1

I have several files stored on my repository. Some are stored via LFS. I want to check that the file I am handling is stored via LFS without downloading it using python-gitlab. Is it possible to do so?

For now, to check if a file is stored via LFS, I can do:

tree = project.repository_tree(recursive=True, all=True)

for item in tree:
    if item["type"] == "tree":
        continue
    print(item)
    file_info = project.repository_blob(item["id"])
    print(file_info)

I get:

{'id': '52c1831a93b09d559a6e8cbff6f5ac0afa4d0b8a', 'name': 'foobar.csv', 'type': 'blob', 'path': 'folder1/folder2/foobar.csv', 'mode': '100644'}
{'size': 132, 'encoding': 'base64', 'content': 'eJ(..)ag=', 'sha': 'c05f64a2f69390bf2fc63157b1d78f5b6f04c37d'}

There is no metadata about the "type" of file (LFS vs no-LFS). So I check the content of the file and I can tell that it is an LFS file because its content is very distinctive:

import base64

content = base64.b64decode(file_info["content"]).decode()
print(content)
version https://git-lfs.github.com/spec/v1
oid sha256:52c1831a93b09d559a6e8cbff6f5ac0afa4d0b8aa38984bd7e4fc6974a5da2bfa018595b1a
size 128782216

However, I want to check that the file is stored via LFS without downloading its content. Is there a way to do so?

vvvvv
  • 25,404
  • 19
  • 49
  • 81

0 Answers0