0
我有一個運行Python腳本的客戶端post-receive git鉤子。該腳本使用GitPython在HEAD和HEAD〜1之間進行區分,找出已更改的文件的名稱,然後撰寫推文以更新關於該更改的跟蹤者。推後GitPython post-receive git鉤子腳本失敗
掛鉤本身只是運行python wikitweet.py
,其中Python的腳本執行繁重的shell腳本。
當我一推後運行在遠程端的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,雖然我不明白爲什麼這會產生問題。
的GIT中的錯誤代碼129指示不正確的參數(http://stackoverflow.com/questions/21733440/start-process-git-returns-strange-129-exit-code)。 Python模塊似乎直接調用git shell命令,而不是使用git庫綁定。遙控器上運行的是哪個版本的git?也許該版本的git不接受與您在本地運行的版本相同的命令標誌。 –
本地版本是1.7.5.4。遠程版本是1.7.12.1.382.gb0576a6。也許我應該考慮更新本地版本。 –
它看起來像如果我從含有回購目錄內的手動運行'git的差異c43a0b831612eb97f097458816d41aaa0506147d HEAD〜1 --abbrev = 40 --full折射率-M --raw --no-color',它工作在兩個本地和遠程端,但如果我在目錄之外運行它,我會得到stderr消息。這可能是一個問題嗎?也許有一個git環境變量需要重置?我嘗試在'post-receive'腳本的目錄中添加'cd',但無濟於事。 –