博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Git自动部署
阅读量:6870 次
发布时间:2019-06-26

本文共 1507 字,大约阅读时间需要 5 分钟。

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

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

另外一篇参考文章:

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

使用 Git Hooks 实现自动项目部署

如何联系我:【万里虎】www.bravetiger.cn 【QQ】3396726884 (咨询问题100元起,帮助解决问题500元起) 【博客】http://www.cnblogs.com/kenshinobiy/
你可能感兴趣的文章
2、Spring开发的jar文件
查看>>
linux -- #!/bin/bash
查看>>
引用程序集没有强名称解决办法
查看>>
poj 2965 The Pilots Brothers' refrigerator
查看>>
子集生成——回溯法的准备篇
查看>>
Python列表的增删改查和元祖
查看>>
实现多线程2
查看>>
【全网最全的博客美化系列教程】03.给博客添加一只萌萌哒的小仓鼠
查看>>
PostgreSQL 行排序详解
查看>>
根据月份,输出对应的季节,并输出至少两个描述该季节的成语和活动
查看>>
python套接字编程基础
查看>>
字符串数据结构算法题-C++
查看>>
VS2010快捷键
查看>>
nstall-Package : 无法找到程序包“MySql.Data.Entity.EF6”
查看>>
linux基础命令(基本维护)
查看>>
纯CSS,table的thead固定,tbody显示滚动条
查看>>
ios 11 12以后下拉刷新不回位的解决方法
查看>>
flask 路由规划(blueprint)
查看>>
JAVA正则表达式:Pattern、Matcher、String
查看>>
微信小程序授权保存到相册功能
查看>>