Git接收/更新钩子和新分支 [英] Git receive/update hooks and new branches

查看:598
本文介绍了Git接收/更新钩子和新分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有'更新'钩子的问题。在新分支的情况下,它将得到一个0000000000000000000000000000000000000000作为'oldrev'。我不知道如何处理这种情况。



我们有这样的要求,即每个提交消息引用一个有效的Jira问题。所以我在中央仓库上安装了一个更新钩子。该钩子获得oldrev和newrev。然后我将这些传递给git rev-list像这样:
$ b $ g $ rev $ list $ oldrev .. $ newrev

这给了我所有转速的列表,然后我可以迭代,做任何我需要做的事情。



问题是,当用户按下一个新的分支时,钩子获取0000000000000000000000000000000000000000作为oldrev。



致命的:无效的修订范围0000000000000000000000000000000000000000..21bac83b2



那么如何获得新分支上所有转速的列表?我已经在网上查了很长一段时间了,什么都没发现。我找到的示例钩子




  • 不能解决问题,并且会失败,并显示上述错误消息

  • 错误地尝试通过将oldrev设置为,从rev-list返回错误结果来解决问题。

  • 当他们遇到oldrev时简单放弃



  • 这些都听起来特别令人兴奋。所以有人有任何想法如何获得在这种情况下的正确答案?我在考虑查询git是否给我所有可从newrev获得的转发,但不能从任何其他分支(=除新分支以外的所有分支)。但即使如此,如果从新分支合并到任何旧分支,这也会给出错误的答案。 解决方案

在这种情况下,术语正确答案有点模糊。我实际上认为所有的新车都可以从新车到达,但没有其他地方是完全正确的。即使存在合并,情况也是如此 - 在这种情况下,您应该看到提交对新引用和合并提交唯一的提交,但不会合并提交。



因此,我会说,检查oldrev是否全为零,如果是,则相应地采取行动:

  if [$ oldrev-eq 0];那么
#列出所有从newrev可到达的但不是任何头的
git rev-list $(git for-each-ref --format ='%(refname)'refs / heads / * | sed's / ^ / \ ^ /')$ newrev
else
git rev-list$ oldrev .. $ newrev
fi


I have a problem with the 'update' hook. In the case of a new branch, it gets a 0000000000000000000000000000000000000000 as the 'oldrev'. And I don't know how to handle that case.

We have the requirement, that every commit message references a valid Jira issue. So I have installed an "update" hook on our central repository. That hook gets an "oldrev" and a "newrev". I then pass those to "git rev-list" like this:

git rev-list $oldrev..$newrev

This gives me the list of all revs, which I can then iterate through, and do whatever I need to do.

The problem is, when the user pushes a new branch, the hook gets 0000000000000000000000000000000000000000 as the oldrev. And "git rev-list" simply complains with:

fatal: Invalid revision range 0000000000000000000000000000000000000000..21bac83b2

So how do I get the list of all the revs that are on that new branch? I have searched the net for quite some time now, and found nothing. The example hooks I found either

  • don't handle the problem, and fail with the above error message
  • incorrectly try to fix the problem by setting the oldrev to "", which returns the wrong results from rev-list
  • simply give up when they encounter that oldrev

None of these sound particularly exciting.

So does someone have any idea how to get the right answer in that case? I was thinking about querying git for "give me all revs that are reachable from newrev, but not from any of the other branches (=all branches except the new one)". But even that would give the wrong answer if there had been a merge from the new branch to any of the old ones.

解决方案

The term "right answer" is a bit ambiguous in this case. I actually think that "all revs reachable from newrev but nowhere else" is completely correct. This is true even if there was a merge - in that case, you should see the commits unique to the new ref, and the merge commit, but not the commits that were merged.

So, I would say, check if the "oldrev" is all zeroes, and if it is, act accordingly:

if [ "$oldrev" -eq 0 ]; then
    # list everything reachable from newrev but not any heads
    git rev-list $(git for-each-ref --format='%(refname)' refs/heads/* | sed 's/^/\^/') "$newrev"
else
    git rev-list "$oldrev..$newrev"
fi

这篇关于Git接收/更新钩子和新分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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