Add pre-receive check to block by file size
I would really like to have the capability to configure a pre-receive hook which can block commits containing any single file larger than X size (e.g. 5MB). The size limit should be configurable, and there should also be an option to ignore files that are going to be stored in git-LFS, as that is where such large files should go.
This should be a fairly simple operation of running git ls-tree on the incoming commits and checking for any files that exceed the size threshold.
Comments (6)
-
reporter -
repo owner This is a great feature request!
(Note: I prefer to keep all the tickets in this one tracker.)
-
reporter - changed title to Add pre-receive check to block by file size
-
repo owner - changed status to resolved
Implemented in v2019.10.12 of Control-Freak
"git ls-tree" didn't work (too difficult to determine net-new files via that approach), but "git rev-list --objects" piped into "git cat-file --batch-check" worked like a charm!
Our implementation has one weakness: if a large binary file that is byte-identical to a file already present in the repository is pushed (even if it's on a dead or unreachable branch), our logic cannot block those, since they don't show up in the "git rev-list --objects" output. But those don't increase the repository size, anyway, thanks to git's de-duplication logic under the hood.
-
reporter Thanks for implementing this so quickly!
I agree that failing to detect large files which are already valid objects in the repository is not a concern. Our primary need is to help prevent new large files from being introduced to the repository, which this does perfectly.
-
repo owner Please don’t hesitate to let me know if you encounter any issues with this (or anything else!)
p.s. If you don’t mind leaving an honest review on marketplace.atlassian.com, that would be really helpful. Here’s the URL for leaving reviews: https://marketplace.atlassian.com/apps/1217635/control-freak-for-bitbucket-server?hosting=datacenter&tab=reviews
- Log in to comment
Hmm, I thought I was submitting this against the ‘Control Freak for Bitbucket Server’ plugin, but the Atlassian Marketplace brought me to the PR-Booster issue tracker instead?
Any way to move this to the Control Freak issue tracker?