Git的commit钩子 - 如何使用commit-msg挂钩,以检查消息字符串? [英] Git commit hook - How to use the commit-msg hook to check for string in message?

查看:3052
本文介绍了Git的commit钩子 - 如何使用commit-msg挂钩,以检查消息字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要提交-msg挂钩,以检查是否提交信息中包含这部分的任何app.asana。我搜索了一些参考文献和文​​件,我知道我需要使用提交-MSG这一点。我有这样的使用Perl或击之作。

I need to make a commit-msg hook to check if the commit message contains "app.asana" in any part of this. I searched some references and documentation and I know I need to use the commit-msg for this. I have to make this using Perl or Bash.

有谁有一个关于这条线索或地方我可以看看更多的例子来学习如何做到这一点?

Does anybody has a clue about this or somewhere I can look more examples to learn how to do it??

感谢您。

推荐答案

我发现一个回答我的问题。如果它可以帮助别人...

I found an answer to my question. In case it may help somebody...

我刚刚创建的.git /钩 A 提交-MSG 文件,其中包含

I just created a commit-msg file in .git/hooks containing

#!/bin/sh

test -n "$(grep 'app.asana.com/' ${1})" || {
        echo >&2 "ERROR: Commit message is missing Asana's task link.\n\nPlease append the Asana's task link relative to this commit into the commit message."
        exit 1
}

每个用户都需要有内部的的.git /钩 A 提交-MSG 文件。那么,作为一个解决方案,我加了提交-MSG 到项目文件夹(这样我就可以完成这)一个名为提交-MSG-钩另一个文件.SH 包含:

Each user needs to have a commit-msg file inside .git/hooks. Then, as a solution, I added commit-msg to the project folder (so I can pull this) with another file called commit-msg-hook.sh containing:

#!/bin/sh

cp commit-msg .git/hooks/commit-msg
chmod +x .git/hooks/commit-msg
echo "\nThe commit-msg hook was added to git hooks"

我欢迎任何建议,以改进我做了什么。谢谢你。

I welcome any advice to improve what I've done. Thanks.

这篇关于Git的commit钩子 - 如何使用commit-msg挂钩,以检查消息字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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