To programatically fetch the uncompressed file size with doing git clone, we can use the following approach -
The below azure DevOps rest api gives us the compressed size only and not the full expanded size of the repository.
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/repositories/list?view=azure-devops-rest-7.1&tabs=HTTP
To calculate the size of the files that are being tracked in GIT lfs as well as the size that are not getting tracked on git lfs we can use the below approach.
We can run the items list api with full recursion and with metadata content.
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/items/list?view=azure-devops-rest-7.2&tabs=HTTP
GET https://dev.azure.com/ {organization}/{project}/_apis/git/repositories/ {repositoryId}/items?recursionLevel=Full&includeContentMetadata=true&api-version=7.2-preview.1
This will give us the full list of all blob object IDs and tree object IDs.
For getting the full uncompresses size of LFS file , we can use the below API call –
https://learn.microsoft.com/en-us/rest/api/azure/devops/git/blobs/get-blob?view=azure-devops-rest-7.0&tabs=HTTP
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/blobs/ {sha1}?$format=octetstream&api-version=7.0
In SHA we will put the object ID for the LFS file that we got from the item list rest API.
For files that are not getting tracked in LFS. We can use the same API will json format instead of octet.
GEThttps://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/blobs/{sha1}?$format=json&api-version=7.0
There is no out of box solution of a single API that you can trigger that will give you the uncompressed file size of all the files in git repo including LFS files. You will have to create a customer script leveraging the above rest APIs that iterates through the objects to fetch size on a file to file basis considering we don’t want to do got clone to get the same information.
git count-objects -vH
– Subedit