Node-Git-Hooks
January 29, 2016 ยท View on GitHub
Examples of Git hooks written in node with script to initialise them. Examples have been tested on OSX, Linux and Windows.
Simply run npm run git:init.
Customisable hooks
There are many.
Examples
- pre-commit: Add a test script to the package.json to see a pre-commit hook running tests before commit.
- pre-push: Try pushing to master to see you fail!
Why Initialise?
git/init.jsis needed to copy over hooks found ingit/hooksinto.git/hooksfolder.- Uses node modules
fsandpathto do so. - This is required as the .git/ file being local and can't be shared over git.
chmod +xis used on each script to allow it to be executable more than one time!
You could just copy and paste but that would be boring and a one liner means your team of developers will be slightly less reluctant to add hooks to their flow!
Suggestions
I have no idea whether what I've done is best practice so please create issues with comments, suggestions and questions.
TODO
- Check to see if any hooks are in place and use renameFileSync to create hook.old files to be used again.