The Wayback Machine - https://web.archive.org/web/20200917114339/https://github.com/github/platform-samples/pull/259
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-receive hook to block commits by size under 50MB #259

Closed
wants to merge 1 commit into from

Conversation

@mzzmjd
Copy link
Contributor

mzzmjd commented Aug 6, 2019

Pre-receive hook to block commits smaller than repo Maximum Object Size setting.

We had a requirement from a user to block any file and any commit that was over 100000 bytes in size.

Obviously the Maximum Object Size setting would be useful for this:

Set the maximum size of Git objects that can be pushed to this repository.
Allowing large objects to be pushed into Git can degrade performance, consider other options
(e.g. git-lfs) before increasing this value.

However, as the minimum value that can be set is 50 MB this was not the way forward.

So knocked up this pre-receive hook. Not sure that it is the most efficient way of doing things, but it seems to work OK.

…ze setting
@stoe
Copy link
Member

stoe commented Aug 7, 2019

Cool addition, @mzzmjd.

Currently it will not work for newly created branches, when e.g. doing a git push -u origin HEAD.

Feel free to take a look at one of the other scripts on how to also capture new branches, for example

zero_commit="0000000000000000000000000000000000000000"
# Do not traverse over commits that are already in the repository
# (e.g. in a different branch)
# This prevents funny errors if pre-receive hooks got enabled after some
# commits got already in and then somebody tries to create a new branch
# If this is unwanted behavior, just set the variable to empty
excludeExisting="--not --all"
while read oldrev newrev refname; do
# echo "payload"
echo $refname $oldrev $newrev
# branch or tag get deleted
if [ "$newrev" = "$zero_commit" ]; then
continue
fi
# Check for new branch or tag
if [ "$oldrev" = "$zero_commit" ]; then
span=`git rev-list $newrev $excludeExisting`
else
span=`git rev-list $oldrev..$newrev $excludeExisting`
fi
for COMMIT in $span;

@jonico
Copy link
Contributor

jonico commented Mar 20, 2020

@mzzmjd: GitHub.com and GitHub Enterprise Server (since version 2.20) now have an ability to restrict the commit size per repository to values smaller than 50 MB,, e.g. 1 MB:
https://help.github.com/en/enterprise/2.20/admin/installation/setting-git-push-limits

I will close this pull request because of this. Feel free to reopen if you believe there is still a reason for a pre-receive hook.

@jonico jonico closed this Mar 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.