格里特改变合并胡克 [英] Gerrit change-merged Hook
问题描述
我使用git作为我的版本控制系统,并且已经建立了一个Gerrit网站来进行代码审查。我想创建一个钩子来执行以下操作:
应该被修改。
$ p $ Change $ id变更标识:Ie1411d50f6beb885bc3d3b7d8c587635e1446c18
将Change-Id替换为新修补程序的Change-Id。
Change-Id:I1c25f7b967084008b69a6a8aefa6e3bb32967b82
,那么脚本运行后, version.txt 文件应包含以下字符串:
#version Change-Id:I1c25f7b967084008b69a6a8aefa6e3bb32967b82
我感觉这个窝可以使用更改合并钩子。我是对的吗?
在此先感谢。
这:
#!/ bin / sh
#请参阅下面的链接以获得实际的命令行格式
#您可能需要使参数解析更健壮
CHANGE_ID = $ 2
git clone $ {GIT_DIR} / tmp / repo - $ {CHANGE_ID}
echo #version Change-Id:$ {CHANGE_ID}> /tmp/repo-${CHANGE_ID}/version.txt
GIT_DIR = / tmp / repo - $ {CHANGE_ID} /
cd / tmp / repo - $ {CHANGE_ID} /
git add /tmp/repo-${CHANGE_ID}/version.txt
git commit -m'Auto-updated version'
git push origin master
rm -rf / tmp / repo - $ {CHANGE_ID } /
http://gerrit-documentation.googlecode.com/svn/Documentation/2.2.2/config-hooks.html#_change_merged 原则上,我不是这种方法的粉丝,我认为应该在出路上做得更好(例如,install.sh脚本,它可以使用git命令来提取修订散列,并从那里生成一个version.txt文件)。但像这样的东西应该把你放在正确的方向。这是未经测试的,但它应该工作。
I use git as my version control system and have set up a Gerrit site to do the code review. I would like to create a hook to do the following:
- When the admin clicks the Submit button, a file (called version.txt) should be modified.
- Script should open the file.
Find the following text (where the ID may change)
#version Change-Id: Ie1411d50f6beb885bc3d3b7d8c587635e1446c18
Replace the Change-Id with the Change-Id of the new patch.
So, if the patch being merged has the
Change-Id: I1c25f7b967084008b69a6a8aefa6e3bb32967b82
then the version.txt file should contain the following string after the script is run:#version Change-Id: I1c25f7b967084008b69a6a8aefa6e3bb32967b82
- Then the hook should create a new commit (since now there has been a change in one of the files) and push this last commit to master.
I feel this would be possible using a change-merged hook. Am I right?
Thanks in advance.
Something like this:
#!/bin/sh
# See link below for actual command line format
# you may need to make the argument parsing more robust
CHANGE_ID=$2
git clone ${GIT_DIR} /tmp/repo-${CHANGE_ID}
echo "#version Change-Id: ${CHANGE_ID}" > /tmp/repo-${CHANGE_ID}/version.txt
GIT_DIR=/tmp/repo-${CHANGE_ID}/
cd /tmp/repo-${CHANGE_ID}/
git add /tmp/repo-${CHANGE_ID}/version.txt
git commit -m'Auto-updated version'
git push origin master
rm -rf /tmp/repo-${CHANGE_ID}/
http://gerrit-documentation.googlecode.com/svn/Documentation/2.2.2/config-hooks.html#_change_merged
On principle, I'm not a fan of this approach, and I think it should be better done on the way out (e.g., a "install.sh" script, which can use git commands to extract the revision hash, and generate a version.txt file from there). But something like this should put you in the right direction. This is untested, but it should work.
这篇关于格里特改变合并胡克的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!