【发布时间】:2012-01-28 19:39:26
【问题描述】:
我正在使用 python 编写一个 post-receive 钩子,它有望用于自动部署我项目中所有更新的文件。本质上,每次推送“部署”分支时,它都会通过 FTP 将更改的文件上传到我的服务器。
这是我目前所拥有的:
def deploy(old, new):
fileList = subprocess.Popen(['git', 'diff', '--name-only', old, new], stdout=subprocess.PIPE)
files = fileList.stdout.read().split('\n')[:-1]
# Switch to the regular repository and pull to it.
os.chdir("/home/git/testrepo")
subprocess.Popen(['git', 'pull'], cwd="/home/git/testrepo")
for file in files:
print file
for line in sys.stdin.xreadlines():
old, new, ref = line.strip().split(' ')
if ref == "refs/heads/deploy":
print "Deploying the new commits now."
deploy(old, new)
else:
print "No need to deploy."
包含这个钩子的仓库是一个裸仓库。然后我在/home/git/testrepo/ 下有另一个存储库,它是该存储库的克隆。
在这段代码中,我尝试将我的工作目录更改为该存储库,然后启动拉取。但是,这不起作用。相反,当我推送并执行挂钩时,我收到以下消息:“致命:不是 git 存储库:'。'”。
关于如何成功拉入此存储库以便我可以将其文件上传到我的其他服务器的任何想法?我尝试过的所有方法都失败了。
【问题讨论】:
-
现在我可以通过使用“--git-dir”作为我所有 git 命令的参数来设置 git 目录来工作。但是,我仍然有兴趣为我的原始问题找到一个实际的解决方案。
标签: python git githooks git-bare