2012-02-25 71 views
0

git更新後掛鉤有一個奇怪的問題。我創建庫我的服務器(/var/www/vhosts/git/master.git)上,並在這個倉庫中添加一個post-update掛鉤用下面的代碼:使用Git部署站點:更新後的掛鉤首次運行,然後再也不會再運行

#!/bin/sh 

echo $1 
echo "*UPDATE*" 

case " $1 " in 
*'refs/heads/master'*) 
    GIT_WORK_TREE=/var/www/vhosts/website.com/sandbox.website.com git checkout -f 
    echo 
    echo "Master was updated!" 
    echo 
    ;; 
esac 

case " $1 " in 
*'refs/heads/sandbox'*) 
GIT_WORK_TREE=/var/www/vhosts/website.com/sandbox.website.com git checkout -f 
    echo 
    echo "Sandbox was updated!" 
    echo 
    ;; 
esac 

我確信這個文件是可執行的。然後,我創建了用我的計算機上的本地存儲庫:

$ mkdir website && cd website 
$ git init 
$ echo 'Testing.' > index.html 
$ git add index.html 
$ git commit -q -m "Initial commit" 
$ git remote add web ssh://[email protected]/var/www/vhosts/website.com/git/master.git 
$ git push web +master:refs/heads/master 

無論出於何種原因,第一個推動工作只是精細/var/www/vhosts/website.com/sandbox.website.com獲取與索引文件,但隨後沒有下面的推動工作更新。我從post-update掛鉤得到迴應,表示「Master已更新!」但目錄實際上並未更新。

對此提出建議?

回答

0

您似乎有權限問題。看看/var/www/*路徑上的權限,並確保您的git用戶有權讀取/寫入/刪除文件。

我已經使用了很多simpler technique(這裏是一個詳細的script),讓我用我的服務器作爲gitolite git的服務器和部署上推,而無需克隆/var/www/myproject路徑上的存儲庫。它在git 1.7.9Ubuntu 12.04.1 LTSApache/2.2.22上爲我工作。

  1. 在服務器上創建rpository:

    mkdir myproject.git && cd myproject.git 
    git init --bare 
    
  2. 配置庫:

    git config core.worktree /var/www/myproject 
    git config core.bare false 
    git config receive.denycurrentbranch ignore 
    
  3. 編輯或創建hooks/post-receive,並使其可以運行

    touch hooks/post-receive 
    chmod u+x hooks/post-receive 
    

以下是文件內容:

#!/bin/sh 
git checkout -f 

你準備做一推,有工作。

我的git用戶名爲git,我的apache使用了ubuntu用戶。我不得不修改Apache的配置上/etc/apache2/conf.d/security(你可以做到這一點上/etc/apache2/http.conf還)包括:

User git 
Group git 

現在我/var/www/myproject部署推送的所有文件,創建具有git:git用戶/組的文件和我的Apache用途要運行相同的用戶/組。

現在你只需重新啓動服務器或做一個service apache2 restart

相關問題