使用gruntjs作为预提交钩子 [英] Use gruntjs as precommit hook

查看:140
本文介绍了使用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有一种方法来触发自定义脚本当某些重要行为发生时。

这篇关于使用gruntjs作为预提交钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆