Git自動部署

Git自動部署文件位於repository下面的hooks裏的post-receivehtml

 

#!/bin/shgit

set -epost

git-update-server-infoorm

gitosis-run-hook update-mirrorsserver

# Check the remote git repository whetherit is barehtm

IS_BARE=$(git rev-parse--is-bare-repository)ip

if [ -z "$IS_BARE" ]; thenrem

         echo>&2 "fatal: post-receive: IS_NOT_BARE"部署

         exit1it

fi

 

 

# Get the latest commit subject

SUBJECT=$(git log -1--pretty=format:"%s")

 

 

# Deploy the HEAD sources to publish

IS_PULL=$(echo "$SUBJECT" | grep"deploy")

if [ -z "$IS_PULL" ]; then

         echo>&2 "tips: post-receive: IS_NOT_PULL"

         exit1

fi

 

 

# Check the deploy dir whether it exists

DEPLOY_DIR=/var/www/htdocs/test_com/

if [ ! -d $DEPLOY_DIR ] ; then

         echo>&2 "fatal: post-receive: DEPLOY_DIR_NOT_EXIST:\"$DEPLOY_DIR\""

         exit1

fi

 

 

# Check the deploy dir whether it is gitrepository

#

#IS_GIT=$(git rev-parse --git-dir2>/dev/null)

#if [ -z "$IS_GIT" ]; then

#       echo>&2 "fatal: post-receive: IS_NOT_GIT"

#       exit1

#fi

# Goto the deploy dir and pull the latestsources

cd $DEPLOY_DIR

#env -i git reset --hard

unset GIT_DIR

git pull

 

提示我:"fatal: Not a git repository: '.'" 
也就是說這個hook腳本執行了cd以後,繼續執行git語句拉取的時候仍是在hooks文件夾下,而不是cd的文件路徑
若是第三句改爲 "env -i git pull",也會提示說env git不是一個命令什麼的.. 
問題是git的hooks裏面默認有一些環境變量,會致使不管在哪一個語句以後執行git命令都會有一個默認的環境路徑,因此解決方法就是 
在git  pull與cd命令之間加上unsetGIT_DIR就搞定了

---------------------------------------------------

另一篇參考文章:

http://www.360doc.com/content/14/0115/17/10058718_345507725.shtml

使用 Git Hooks 實現自動項目部署

相關文章
相關標籤/搜索