使用gruntjs作为预提交钩子

使用gruntjs作为预提交钩子

问题描述:

是否有一种方法可以运行gruntjs任务作为预提交挂钩。例如,我想阻止提交失败的测试或jshint问题。我也想为每一次提交运行代码美化工具。

Is there a way to run a gruntjs task as precommit hook. For example I want do prevent commits with failing tests or jshint issues. I've also think about to run a code beautifier for every commit.

Git钩子只是在执行类似commit的操作时执行的脚本。它们可以包含任何您想要的编程语言。

Git hooks are just scripts executed when you do an action like commit. They can contain whatever programming language you'd like.

触发grunt的示例:

Example of triggering grunt:

#!/bin/sh
grunt

将其保存到文件中: .git / hooks / pre-commit

如果grunt退出的错误代码高于0,如果任何任务失败,它会阻止提交:

If grunt exits with an error code higher than 0, which it does if any task fail, it will prevent the commit:


从此钩子退出非零将中止提交

Exiting non-zero from this hook aborts the commit






阅读材料: http://codeinthehole.com/writing/tips-for-using-a-git-pre-commit-hook/

以及git文档: http://git-scm.com/book/en/Customizing-Git-Git-Hooks


赞许多其他的版本控制系统,Git有一种方法来触发自定义脚本当某些重要行为发生时。