为什么Gerrit不会将change-id包含在合并提交中? [英] Why does Gerrit not include the change-id into merge commits?

查看:401
本文介绍了为什么Gerrit不会将change-id包含在合并提交中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以git钩子只会将更改ID提交到提交中。虽然可以将合并提交推送到审查分支,但即使Gerrit被配置为在提交消息中需要Change-Id。并且当一个合并提交被推送时,所有后续提交将取决于合并提交 - 因为没有更改Id。那么,为什么不把变更Id包含到合并提交中?

解决方案

prepare-commit-msg msg 被调用(任何)合并提交。所以我现在做Gerrit的 Change-Id 也添加到没有冲突的合并提交中是使用 prepare-commit-msg

 #!/ bin / sh 

if [$ 2 =merge-a -f .git / MERGE_MSG];然后
#显式调用Gerrit的commit-msg钩子以进行合并提交。
.git / hooks / commit-msg$ 1
fi

检查 .git / MERGE_MSG 确保在修改合并提交时不会调用 commit-msg ,因为在那无论如何,该钩子直接被Git调用。请注意,对于 冲突的合并提交,这种方法会导致 commit-msg 被调用两次,一次是在提交冲突解决之后调用 commit-msg 时,prepare-commit-msg 钩子并且一次由Git执行,但这不会导致任何问题。 Gerrit的 commit-msg 钩子检查是否已经添加了 Change-Id 并且不会再添加它,如果这是如果你现在问你自己为什么Gerrit不只是简单地使用 prepare-commit-msg hook来添加 Change-Id ,我想这只是为了防止用户意外删除 Change-Id 来自提交消息。在编辑器关闭后将它作为 commit-msg 钩子的一部分添加它更安全。


so the git hook only puts change Id into commits. Although merge commits can be pushed to review branch even Gerrit is configured to require Change-Id in the commit messages. And when a merge commit has been pushed all the subsequent commit will depends on the merge commit - since there is no change Id. So what is the purpose not to include change Id into merge commit?

解决方案

The underlying problem in Git is that commit-msg hooks are not called for merge commits without conflicts.

However, the prepare-commit-msg is called for (any) merge commits. So what I currently do to get Gerrit's Change-Id also added to merge commits without conflicts is to use a prepare-commit-msg hook like this:

#!/bin/sh

if [ "$2" = "merge" -a -f .git/MERGE_MSG ]; then
    # Explicitly call Gerrit's commit-msg hook for merge commits.
    .git/hooks/commit-msg "$1"
fi

The check for .git/MERGE_MSG ensures that commit-msg will not be called if amending a merge commit, because in that case that hook is called directly by Git anyway. Note that for merge commits with conflicts this approach will result in commit-msg being called twice, once as part of this prepare-commit-msg hook and once by Git when it calls commit-msg after committing the conflicts resolution, but that does not cause any problems as Gerrit's commit-msg hook checks whether the Change-Id has already been added and does not add it again if that's the case.

If you're now asking your self why Gerrit does not simply use only a prepare-commit-msg hook to add the Change-Id, I guess that just to prevent the user from accidentally deleting the Change-Id from the commit message. Adding it as part of a commit-msg hook after the editor has closed is just safer.

这篇关于为什么Gerrit不会将change-id包含在合并提交中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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