git hook:确保每个合并到master中的消息也都自动合并 [英] git hook: ensure each merge into the master has a message also the automatic merges

查看:511
本文介绍了git hook:确保每个合并到master中的消息也都自动合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的部署过程中,最后的步骤将是发布分支到主分支的合并。

我想通过一个钩子来确保这些合并中的每一个都需要提交中的手动消息,因此合并人员有机会写下什么样的一般更改会通过合并进入主人。又名Change.log或发行说明。



到目前为止,我发现我需要的是预合并。
https://gitorious.org/git/mjg/commit/c15bfac6d3f5a28b3cd5745fef71e7f93bc1f8a4
只能在合并到主分支时激活它。我想它也应该在非主动提交到主服务器时进行调用。

有没有人提示我该怎么做?一个bash挂钩是首选,但php也很好。或者我从其他语言中猜测,我可以尝试将该概念翻译成bash或php。

感谢您提前提供任何提示!

解决方案

这里承诺的是我的解决方案。

 #!/ bin / bash 
#give给你的commit.msg钩子过去并适应你的需求。我目前正在处理的分支
mybranch =`git rev-parse --abbrev-ref HEAD`

#根据分支我们做不同的验证
if [$ mybranch = master];那么
regex =^ [^合并| ^#]。{71,}
message =错误:提交消息太短。
else
regex =^(PMS | GKM) - [0-9] {3,4} \s\:\s。{10,}
message = 错误:提交消息缺少格式为GKM-nnnn:或PMS-nnnn:的票证号码。
fi

test!=$(grep -E $ regex$ 1)|| {
cat $ 1>& 2
echo>& 2 $ message
exit 1
}

根据分支,我选择不同的正则表达式和匹配的错误消息。

这可以确保任何分支不被主人,该消息以票号开始。对于主分支,我们不需要票号,但需要更长的提交消息。

In our deployment process on of the last steps will be a merge of the release branch into the master branch.

I want to ensure via a hook, that each of these merges needs a manual message in the commit, so the person merging has the opportunity to write down what general changes will go into the master with this merge. Aka Change.log or release notes.

I found so far that the hook I would need would be the pre-merge. https://gitorious.org/git/mjg/commit/c15bfac6d3f5a28b3cd5745fef71e7f93bc1f8a4 It should only be activated when merging into the master branch. I guess it also should be called when a non-automatic commit into the master takes place.

Has anybody some hints how I can do that? A bash hook would be preferred, but php is also fine. Or I guess from other languages I can try to translate the concept to bash or php.

Thank you for any hints in advance!

解决方案

as promised here is my solution. Past this in your commit.msg hook and adapt to your needs.

#!/bin/bash
# give me the branch I am currently working on
mybranch=`git rev-parse --abbrev-ref HEAD`

# Depending on the branch we do different validation
if [ $mybranch = master ]; then
regex="^[^Merge|^#].{71,}"
message="ERROR: Commit message is too short."
else
regex="^(PMS|GKM)-[0-9]{3,4}\s\:\s.{10,}"
message="ERROR: Commit message is missing the Ticketnumber in the format GKM-nnnn: or PMS-nnnn :."
fi

test "" != "$(grep -E $regex "$1")" || {
    cat $1 >&2
    echo >&2 $message
    exit 1
}

Depending on the branch I choose different regular expressions and matching error messages.

This ensures for any branch not being master, that the message starts with a ticket number. For the master branch we don't need a ticket number, but a longer commit message.

这篇关于git hook:确保每个合并到master中的消息也都自动合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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