2

I have the following setup for my post commit hook:

in .git/hooks/push-to-staging

#!/bin/sh

while read oldrev newrev refname
do
  branch=$(git rev-parse --symbolic --abbrev-ref $refname)
  git push -f myapp $branch:master && heroku run rake db:migrate -a my-app && heroku restart -a my-app
done

I made sure to chmod +x push-to-staging.

However, when I push to any of my branches, the push goes fine obviously ... but that's it. I don't see the push to my staging server happening.

Secondly, I'm wondering if there is a way to make this post commit hook a part of my repo (or is that not how hooks are supposed to work?). I just want everyone on my team to have this setup basically.

4

1 回答 1

0

Git 中没有这样的钩子:push-to-staging. 您可以在存储库的目录中看到可用的挂钩hooks,例如在我的系统中:

applypatch-msg
commit-msg
post-commit
post-receive
post-update
pre-applypatch
pre-commit
prepare-commit-msg
pre-rebase
update

在您的情况下,您正在寻找post-commit钩子。将脚本重命名为,或从指向您的脚本post-commit创建符号链接。post-commit

您不能将钩子作为存储库的一部分,也就是说,不能自动启用钩子并通过分支操作传播。如果这是可能的,那么在克隆存储库时将是一个巨大的安全风险。相反,您可以做的是轻松启用钩子脚本,您可以在这些其他答案中看到示例:

将 git 钩子放入存储库

跟踪 .git/hooks 中的钩子的变化

于 2013-06-27T19:53:36.670 回答