正如你们许多人可能知道的那样,git中只能有一种钩子类型.如果需要评估两个更新挂钩.git管理员留下了两个无法管理的解决方案:
exec我正在寻找一个优雅的解决方案(用BASH编写),类似文件夹hooks/update.d或者hooks/post-receive.d允许松散耦合钩子评估.一旦挂钩失败,链接就应该停止.
我实际上在这个URL上找到了一个用Perl编写的可接受的解决方案http://blog.bluefeet.net/2011/08/chained-git-hooks
问题:我的服务器运行不同版本的perl,我得到perllib版本不匹配.它失败.
Oli*_*alo 33
经过进一步调查和测试,这是一个有效的解决方案:
.git/hooks/hook-chain按如下方式创建文件
#!/bin/bash
#
# author: orefalo
hookname=`basename $0`
FILE=`mktemp`
trap 'rm -f $FILE' EXIT
cat - > $FILE
for hook in $GIT_DIR/hooks/$hookname.*
do
if test -x "$hook"; then
# echo $hook
cat $FILE | $hook "$@"
status=$?
if test $status -ne 0; then
echo Hook $hook failed with error code $status
exit $status
fi
fi
done
Run Code Online (Sandbox Code Playgroud)
现在链接任何需要链接的钩子
最后,通过将它们重命名为创建链hookname.action
-rwxr-xr-x. 1 git git 6710 functions
-rwxr-xr-x. 1 git git 280 hook-chain
-rwxr-xr-x. 1 git git 1524 post-mirror
lrwxrwxrwx. 1 root root 10 post-receive -> hook-chain
-rwxr-xr-x. 1 git git 8763 post-receive.1email
-rwxr-xr-x. 1 git git 1745 post-receive.2github
-rwxr-xr-x. 1 git git 473 post-upload-pack
-rwxr-xr-x. 1 git git 346 pre-receive
lrwxrwxrwx. 1 root root 10 update -> hook-chain
-rwxr-xr-x. 1 git git 2975 update.1acl
-rwxr-xr-x. 1 git git 328 update.2github
Run Code Online (Sandbox Code Playgroud)
例如,在上面的示例中,update hook将运行update.1acl,然后运行update.2github.
在后收到钩与运行-receive.1email后,接着,receive.2github后
| 归档时间: |
|
| 查看次数: |
4606 次 |
| 最近记录: |