Recently, the accounting of Bitbucket resources has changed a bit, so that the first 33kB of an empty repository is reflected in the size reported by the repositories call. A customer has the following to say:
We’ve previously been using the repositories API endpoint to fetch details about repositories and specifically their size and if they’re empty, until recently empty repositories used to return 0 as their size however recently they’ve been returning sizes - whats changed?
How would you now suggest one detects if a repository is actually empty or not? Any plans to implement an `empty?` boolean?
While the disk size (bytes) does have a correlation to the repo's content, it is too simple to assume that an empty repo takes up zero bytes.
Even an empty repo contains the basic SCM files and so is not 0 bytes. Nor is it necessarily deterministic as a newer version of the SCM might format these files slightly differently and so show a slightly different size.
@john-garcia-atlassian makes good suggestions. An empty repo has no commits and so I'd just check for that:
$ curl -s https://api.bitbucket.org/2.0/repositories/evzijst/emptygit/commits | jsonify { "page": 1, "pagelen": 30, "values": [] }
If the "values" element is empty, the repo contains no commits.
For extra credit, add "?pagelen=1" to reduce the amount of response data in case the repo is not empty ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There's actually a few different ways to determine if a repository is empty.
- The branches resource can be used; if it returns anything other than empty set, the repo is not empty.
- The main-branch endpoint returns No main branch set
- The changesets endpoint will return 404
I'm sure there are others, but we hope this list will get you started.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, guys, for documenting this on Answers!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.