我最近需要编写git hooks,用于引用特定票证的所有提交.
我希望有一个地方可以开始学习.pro git书中的所有内容都是用Ruby编写的.由于Ruby不是我强大的西装,任何人都可以分享有关用其他语言编写的git hook的教程吗?(我特别喜欢Python或Bash脚本.)
git附带的例子是用shell脚本编写的; .git/hooks每个仓库中都有一些基本的,并且安装了更高级的仓库/usr/share/doc/git-core/contrib/hooks.
还有更多关于各种钩子的信息$ man githooks.
我发现在python上编写git hook很容易.这是python上的post-receive hook的一个例子.提供的示例在不同文件夹中部署master和develop 分支(master中的更改将被推送到生产网站,develop分支中的更改将被推送到qa站点)
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#post-receive
import sys
import subprocess
# 1. Read STDIN (Format: "from_commit to_commit branch_name")
(old, new, branch) = sys.stdin.read().split()
# 2. Only deploy if master branch was pushed
if branch == 'refs/heads/master':
subprocess.call('date >> ~/prod-deployment.log', shell=True)
subprocess.call('GIT_WORK_TREE=/home/ft/app.prod git checkout master -f', shell=True)
subprocess.call('cd ../../app.prod;bower update', shell=True)
#3. Only deploy if develop branch was pushed
if branch == 'refs/heads/develop':
subprocess.call('date >> ~/dev-deployment.log', shell=True)
subprocess.call('GIT_WORK_TREE=/home/ft/app.dev git checkout develop -f', shell=True)
subprocess.call('cd ../../app.dev;bower update', shell=True)
Run Code Online (Sandbox Code Playgroud)