Add pre-receive check to block by file size

Issue #95 resolved
Jeffrey Thornsen created an issue

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)

  1. Jeffrey Thornsen reporter

    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?

  2. Julius Davies [bit-booster.com] repo owner

    This is a great feature request!

    (Note: I prefer to keep all the tickets in this one tracker.)

  3. Julius Davies [bit-booster.com] repo owner

    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.

    block-large-files.png

  4. Jeffrey Thornsen 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.

  5. Log in to comment