2011-06-08 23 views
3

我一直在研究Kohana 3項目,我之前使用下載的zip文件進行安裝。我有我的遠程服務器「project.git」,檢查出最新提交的工作目錄「的public_html」在我測試應用程序一個Git倉庫GIT post-receive hook不檢出子模塊

我的後收到鉤文件

GIT_WORK_TREE=/var/www/public_html; 
git checkout -f; 

這工作了幾個月,直到我決定刪除一些kohana文件夾並使用git子模塊,所以我可以通過git進行更新。

現在問題是子模塊不在工作目錄中。我試着在那裏添加子模塊,但「public_html」目錄不是存儲庫。在「project.git」目錄中,git命令會拋出一個錯誤,我必須在工作目錄中執行它們。

我如何在進行提交時修改鉤子以檢出子模塊?

更新

按@ manojlds的建議: 我把它添加到鉤子,現在它看起來像這樣:

GIT_WORK_TREE=/var/www/public_html; 
git submodule init; 
git submodule update; 
git checkout -f; 

但我得到這個消息,

remote: You need to run this command from the Top level of the working tree 

並且沒有更改子模塊

public_html 
+0

爲了以防萬一,一切工作正常本地。我只是想讓遠程Web文件夾擁有我在本地的所有東西 – 2011-06-08 17:35:58

+0

是的我能夠重現您的問題。用完整的post-receive hook查看我的更新回答。 – manojlds 2011-06-08 20:18:41

回答

1

Th是我的post-receive鉤子: 將WORK_DIR替換爲您要結賬的位置。這是我的案例中的主要網站目錄。它被初始化爲一個git倉庫,並且簡單地從這個鉤子運行的git裸倉庫中取出。這樣可以解決檢出速度問題(git比cp-R更快地檢查出另一個答案),並且保持子模塊正確同步。

#!/bin/sh 
unset GIT_DIR 
echo "Checking out" 
(cd $WORK_DIR && git pull --recurse-submodules=yes --force) 
echo "Submodule update..." 
(cd $WORK_DIR && git --work-tree="$WORK_DIR" submodule update --init --recursive --force) 
4

你必須添加以下(適當地使用GIT_WORK_TREE環境varible):

git submodule init 
git submodule update 

,這樣你可以得到遠程服務器上的子模塊的內容,然後將它們複製到public_html

以下是完整的接收後掛鉤(修改爲支持子模塊的正常運行):

#!/bin/sh 
unset GIT_DIR 
git clone /path/to/repo /tmp/public_html 
cd /tmp/public_html 
git submodule init 
git submodule update 
cp -R /tmp/public_html /var/www/ 
rm -rf /tmp/public_html 
rm -rf /var/www/public_html/.git 
+0

是的,我嘗試過,但它不能在project.git文件夾中工作,也不能在public_html文件夾中工作。我是否將其添加到鉤子文件本身? – 2011-06-08 17:50:32

+0

@ Jay8100是加入鉤子本身。 – manojlds 2011-06-08 17:51:09

+0

我會編輯問題 – 2011-06-08 17:56:42