LF provides Git/Gerrit as SCM/Code Review tools. Please click this link to access Gerrit.
Is it possible to limit the file size within a commit in a git repository? We want to protect against the mistake of trying to commit files which should not go into a VCS (e.g. big file system images).
http://gregmac.net/git/2013/06/13/locating-large-objects.html ←- lists some of the git utilities that can be used to identify large files in your repository. In this post we show how to create a server-side hook that will block large files before they get into your repo. Some of the same utilities from the post referenced above will be used in creating this hook.
Git hooks allow you to perform actions at different points in the git push workflow. Server-side hooks are executed at certain specific phases of the push process:
Fires before any refs are updated on the server, and is run once. This hook receives a list of changes on stdin in the format of: old-ref new-ref refname, one line for each ref to be updated. Both stderr and stdout are forwarded back to the user for messaging. A non-zero exit will prevent any refs from being updated.
Fires before the updating the refs on the server, and is executed once for each ref that is being updated. It takes 3 arguments: ref-name old-ref new-ref, and will pass stderr and stdout back to the client. A non-zero exit status will only prevent the effected ref from being updated on the server.
Fires once after all refs have been updated, and gets the same input on stdin as the pre-receive hook. As with the hooks before it, stdout and stderr are passed back to the client for messaging. Generally this type of hook is only used for notification and/or messaging to clients about the push that just occured.
As with the post-receive hook, this fires once after the refs have been updated, and takes a variable number of arguments. Each parameter that is passed in, is the name of a ref that was successfully updated. Similarly to post-receive this hook is also used primarily for notification, as it cannot effect the status of the push.
On the git server these hooks live inside the hooks directory of the bare repository. They must to be named to match the type of hook they are.
Since we’re looking to block an actual commit from happening, we would want to use either a pre-receive or update hook. The distinction here is that the pre-receive will block all updates on a non-zero exit, whereas the update will only block the specific update for the ref which returns a non-zero exit. For this example I will choose to use pre-receive because I want to block the entire push if we find an object that is over the file size limit.