全量更新当前目录下所有GIT目录
sh gitpull.sh
#/bin/sh
#全量更新当前目录下素有其它目录
ls
pwd
echo "你将更新以上git目录的当前分支"
echo -e "请输入确认[y/n]:"
dirNameBase=${PWD}
read sure
if [[ $sure != 'y' ]]; then
echo "已取消,退出本次部署"
exit
fi
modifiedDirArray=()
for k in $(ls $(pwd))
do
cddir="${dirNameBase}/${k}"
cd ${cddir}
dirName=${PWD##*/}
echo "dirName=${dirNameBase}/${k}"
gitStatus=$(git status)
if [[ $gitStatus == *repository* ]]
then
echo "$dirName 目录不是git仓库"
cd ..
continue
fi
gitBranch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
echo "操作模块:" $dirName "中..."
if [[ $gitStatus == *modified* ]]
then
modifiedDirArray+=($dirName)
echo " 当前分支: ${gitBranch} 存在未提交代码,请手动更新"
else
git pull &> /dev/null
echo " 当前分支: ${gitBranch} 已经升级到最新"
fi
cd ..
done
modifiedCount=${#modifiedDirArray[@]}
if [ $modifiedCount -eq 0 ]; then
echo "所有模块的当前分支都已经更新到最新"
else
echo "以下 $modifiedCount 个模块未完成更新:"
printf '%s\n' "${modifiedDirArray[@]}"
fi