Git自動部署

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


#!/bin/sh

set -e

git-update-server-info

gitosis-run-hook update-mirrors

# Check the remote git repository whetherit is bare

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

if [ -z "$IS_BARE" ]; then

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

         exit1

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就搞定了


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章