How to protect against clicking large binary drops in git?

I have a central git repository that I and several collaborators regularly click and pull. I used to make a large binary blob by accident, which requires a full recovery, and this is a pain for everyone, so I would like to protect against this in the future. Is it possible to set the hook in the remote repository, which will check the file size of the pressed files (are they added to a new one or the existing file is updated) and reject the sense with the files above the threshold size, say 2 MB?

It is important that existing files are already more than 2 MB, which were not transferable (therefore, you cannot drop push if the 2MB file is already in the repository, only if push adds a 2 MB file or extends an existing file up to 2 MB). In addition, I want the host to run on the remote side, so I don’t have to worry about the fact that clients do not need to set hooks.

Edit: since push can contain multiple commits, and even one commit with a large file is stuck in the repo, I want to protect against push that contain / any commit /, which grows or adds a file> = 2MB.

+6
source share
1 answer

It seems that pre-receive hook will be the right place for this check. This hook is executed on the server side of the push and has access to sufficient information to implement file size verification.

This hook is called by git -receive-pack in the remote repository, which happens when git push is executed in the local repository. Before updating refs, the pre-receive hook is launched in the remote repository. Its exit status determines the success or failure of the update.

+5
source

Source: https://habr.com/ru/post/920829/


All Articles