How can I check the size of a repository on Azure DevOps?
Asked Answered
E

2

6

I would like to check the size of a remote repository without downloading it to my local disk. GitLab automatically displays the size of the repository, including a breakdown of Git files and Git LFS files. Is this also possible on Azure DevOps?

I have searched for a solution online and the only solution I found was to download the repository to my local disk and run the "git count-objects -vH" command.

Ephraim answered 17/2, 2023 at 16:35 Comment(2)
As of now I don't think there is any out of the box option for size in ADO, but you could setup a simple pipeline that would display the size of the repository using git count-objects -vHSubedit
Thank you, I wanted to check, but an error occurred stating that no hosted parallelism has been purchased or granted. I have submitted a request and am waiting for approval to find out the size of the repositoryEphraim
U
0

Additionally, you can try the rest api: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/repositories/list?view=azure-devops-rest-7.1&tabs=HTTP

size - integer - Compressed size (bytes) of the repository.

As an example:

enter image description here

Ulberto answered 18/2, 2023 at 17:35 Comment(3)
Does the size include git LFS files? I checked the repository size and if it's in bytes, it's definitely too small and doesn't reflect the size of files in git and git LFSEphraim
Does the Azure rest api allow for retrieving information about the size of LFS files?Ephraim
maybe not.. because there is a separate API where you can see the size of lfs file: learn.microsoft.com/en-us/rest/api/azure/devops/git/blobs/… with resolveLfs={resolveLfs}Ulberto
K
0

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

enter image description here

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

enter image description here

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.

enter image description here

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.

enter image description here

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

enter image description here

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.

Kellykellyann answered 15/2 at 17:52 Comment(1)
The fact that Azure DevOps doesn't offer a simple summary showing the repo size in the UI is insulting and just lazy management. They can't even be bothered to give an Azure toolbar to get back to the rest of services.Supernova

© 2022 - 2024 — McMap. All rights reserved.