简体   繁体   中英

git lfs pre-receive hooks to prevent unwanted files in repository

Is it possible to write a server side pre-receive hook to prevent large or binary files to be added to the repository via commits?

Locally I can control git-lfs behaviour by adding file types to a .gitattribute file via:

    git lfs track "*.zip"

This would cause that if a new zip file is added, it will be managed by git-lfs and not committed to the git object store.

git-p4 even allows me file size thresholds like:

    largeFileCompressedThreshold = 1m
    largeFileThreshold = 50m

With multiple developers and developing environments it might happen, that one adds such a binary file without configuring git-lfs, hence such a file could be submitted to git directly. I would like a server side hook which refuses such a commit and gives a meaningful message, so the developer can easily identify the problem.

Ideally this receive hook would use existing git functionality to parse eg .gitattributes instead of manually parsing all files which are being committed in a script.

This could be accomplished using the sizelimit directive of the CheckFile plugin from the Git-Hooks framework. We use it and it works really well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM