Allows you to restrict the maximum file size of an individual file. This is important because once pushed and accepted, all files will stay in the repo forever. It will be transmitted to anyone that clones the repo, increasing the amount of time for the checkout operation, and increasing their disk space requirements.

> git push
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 258.45 KiB | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: =====================================================================
remote: File too large (max size 1048576 bytes): largefile.bin
remote: =====================================================================
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ''

This can be combined with a condition so that certain users are allowed to push large files.

This can take some time when pushing a new repository, as the size of every file in each commit needs to be checked. During testing we were able to push the Groovy Core repository in around 1 minute on a fresh instance of Bitbucket Server. This type of performance can be expected from version 4.3.17 onwards due to this fix: SRBITB-187.

To check the progress of a large push you can enable debug logging for com.onresolve.scriptrunner.canned.bitbucket.hooks.MaxFilesizeHook. It will show you in the logs how many commits have been processed so far for a particular repository.

Exclude Files Tracked by Git LFS

You can exclude files tracked by Git LFS from the restrict file size hook by selecting the Exclude LFS files checkbox.

Using the restrict file size hook in this way will indicate to the developer which files need to be moved to LFS.