繁体   English   中英

推送后GitPython的接收后git hook脚本失败

[英]GitPython post-receive git hook script fails after push

我有一个运行Python脚本的客户端后接收git钩子。 该脚本使用GitPython在HEAD和HEAD〜1之间进行区分,找出已更改文件的名称,然后编写一条推文,以更新有关更改的关注者。

挂钩本身只是一个运行python wikitweet.py的shell脚本,其中Python脚本python wikitweet.py了很多工作。

推送后在远程运行Python脚本时,一切正常。 但是当我从本地推送时,出现以下错误:

remote: Traceback (most recent call last):
remote:   File "/home/wcm1/bin/wikitweet.py", line 21, in <module>
remote:     most_recent_diff = repo.head.commit.diff('HEAD~1')
remote:   File "/usr/lib/python2.6/site-packages/git/diff.py", line 111, in diff
remote:     proc.wait()
remote:   File "/usr/lib/python2.6/site-packages/git/cmd.py", line 309, in wait
remote:     raise GitCommandError(self.args, status, self.proc.stderr.read())
remote: git.exc.GitCommandError: 'git diff c43a0b831612eb97f097458816d41aaa0506147d HEAD~1 --abbrev=40 --full-index -M --raw --no-color' returned with exit code 129
remote: stderr: 'usage: git diff [--no-index] <path> <path>
remote: '

之后,完成对母版的推送和复制工作的更新就可以了。 我可以从该错误消息中的提交哈希值得知该脚本已成功获取新的HEAD提交,因此,似乎何时运行该挂钩都不是问题(我不认为)。

我猜想我要么是对钩子的误解,要么是在我的Python脚本中做错了什么,但是很难理解为什么它在远程运行,但在推送后失败。 这是wikitweet.py中似乎引起问题的相关行:

repo = git.Repo('/path/to/repo')

most_recent_diff = repo.head.commit.diff('HEAD~1')
changed_files = []
for x in most_recent_diff:
    if x.a_blob.path not in changed_files:
       changed_files.append(x.a_blob.path)
    if x.b_blob is not None and x.b_blob.path not in changed_files:
       changed_files.append(x.b_blob.path)

    [...]

我也有在远程和本地运行的不同版本的Python,尽管我不明白为什么这会引起问题。

我收到一个标准错误,因为使用post-receive挂钩时git设置了环境变量。 解决方法是将此行添加到我的钩子中:

unset GIT_DIR

该页面提供了一些有关钩子和环境变量的有用提示,这些提示可以帮助我解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM