合并两个 post-receive hooks

Combine two post-receive hooks

如何组合两个 post-receive 挂钩?第一个是 git-slack integration 并使用以下循环运行:

while read line
do
  set -- $line
  notify $*
  RET=$?
done

第二个用于我的部署,如下所示:

while read oldrev newrev refname line
do
   branch=$(git rev-parse --symbolic --abbrev-ref $refname)
   if [ "master" = "$branch" ]; then
     # some deployment commands
   elif [ "development" = "$branch" ]; then
     # some other deployment commands
   fi
done

无论 git 使用哪个分支,我都希望能够向 slack 发送通知。

关于如何组合两个循环的任何提示?

这还没有经过测试,但应该可以工作:

while read oldrev newrev refname line
do
  set -- "$oldrev $newrev $refname $line"
  notify $*

  # Not sure the return value is needed since it isn't being used anywhere
  RET=$?

  branch=$(git rev-parse --symbolic --abbrev-ref $refname)
  if [ "master" = "$branch" ]; then
    # some deployment commands
  elif [ "development" = "$branch" ]; then
   # some other deployment commands
  fi
done

希望对您有所帮助