Closed
Description
Bug Description
When using the file-contents
API to request information about a directory, the returned JSON always sets the "size"
field to 0
for directories. This is misleading, as the Git tree object for the directory does have a size, which can be retrieved using native Git commands.
Example response:
[
{
"name": "batch_test",
"path": "batch_test",
"sha": "46b22fae3e0ac92b73989ca912a6d7dacd3975ab",
"type": "dir",
"size": 0,
...
}
]
Expected Behavior
The "size"
field for a directory should reflect the actual size of the corresponding Git tree object, which can be obtained using the following Git command:
git cat-file -s $(git rev-parse HEAD:batch_test)
This would provide the real byte size of the tree object, rather than always returning 0
.
Why is this important?
- Returning the actual tree object size is more accurate and useful for clients that want to understand the underlying Git data structure.
- It aligns the API response with the real state of the repository, and is consistent with how file blobs are handled.
Steps to Reproduce
- Create a directory in a repository.
- Query the
file-contents
API for that directory. - Observe that
"size"
is always0
, regardless of the actual tree object size.
Suggested Fix
- For entries of
"type": "dir"
, set the"size"
field to the size of the corresponding Git tree object, as returned bygit cat-file -s <tree-oid>
.
Additional Information
- Gitea version: Latest
- Example API endpoint:
/repos/{owner}/{repo}/file-contents
Thank you for your attention!