2

我正在使用 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 存储库:'。'”。

关于如何成功拉到此存储库的任何想法,以便我可以将其文件上传到我的其他服务器?我尝试过的每种方法都失败了。

4

1 回答 1

0

The git diff ... is failing because it's not aware you're inside a bare repo.

Try git --bare diff ... instead or setting $GIT_DIR.

于 2011-12-28T15:11:45.777 回答