#!/bin/sh Branch=master Tag="" # 客户端根路径 client_path="./" # 开关 【0】不拉取 【1】冲突不拉取 【2】强拉、覆盖 client=2 # 标签 t_client=$Tag # 路径配置 # 远程Git g_client="http://admin@192.168.1.20:10010/r/snxx_server.git" # 无则创建;且拉取最新 # $1 路径 # $2 git地址 # $3 标签 cloneAll() { if [ $1 = 0 ]; then return; fi echo echo "====================" echo "path:"$2 echo "git:"$3 echo "tag:"$4 echo "====================" # 不存在路径就创建 if [ ! -d $2 ];then echo "第一次创建" git clone $3 $2 fi # 拉取 cd $2 git stash git pull --progress -f # 无标签 if [ -z $4 ];then if [ $1 = 2 ];then git checkout -B $Branch origin/${Branch} -f else git checkout -B $Branch origin/${Branch} fi else #删本地标签 git tag -d $4 git pull --progress -f #切分支 git checkout -B $Branch origin/${Branch} -f #切标签 git reset $4 --hard fi } copyHooks() { if [ $1 = 0 ]; then return; fi echo $1 root=$1 echo root fileFrom=${root}"/Hooks/commit-msg" fileTo=${root}"/.git/hooks/commit-msg" echo $fileFrom echo $fileTo cp $fileFrom $fileTo } # client 一定要拉取 if [ ! -d ${client_path} ]; then mkdir ${client_path}; fi if [ "`ls -A $client_path`" = "" ]; then rm -rf $client_path; fi cloneAll $client $client_path $g_client $t_client copyHooks $client_path echo read -p "操作完成,点Enter键退出"