2012-01-24 75 views
3

我希望能夠執行一個PHP掛鉤後接收掛鉤,將文件從git repo複製到同一服務器上的web文件夾,並且只有在被推入時才運行一個主分支忽略其他分支。以下是我到目前爲止所做的。git後接收掛鉤在php

!/usr/bin/php 
<?php 

exec("git archive master | tar -x -C /var/www/", $output); 

?> 

基本上,即時通訊不知道如何訪問使用php的git參數。

+0

1,因爲Git是:它通過標準輸入的形式傳遞的參數中真棒,我不想研究細節。希望別人會照顧這個很快,我們都可以變得更聰明:) – rdlowrey

+0

a)抓住你選擇的git庫b)學習一些bash – Reactormonk

+0

好的。編號喜歡使用PHP,如果它對你完全一樣。 – madphp

回答

0

不要忘記post-receive鉤子doesn't take arguments:它讀取stdin上的數據。

「接收後」腳本在接收包已接受包並且存儲庫已更新後運行。

<oldrev> <newrev> <refname> 

所以,你需要閱讀該參數extract the branch(例子是在bash,但你能適應它)

+0

從一個PHP腳本從標準輸入讀取:http://stackoverflow.com/questions/554760/php-standard-input,或http://stackoverflow.com/questions/2390604/how-to-pass-variables-as -stdin-into-command-line-from-php if'php:// stdin' is not the right stream to read from。 – VonC