描述
指定git项目的父级目录,遍历目录下的所有工程,批量拉取代码
sh git_batch_pull.sh $1 $2
- 参数$1:目录
- 参数$2:需要进几次目录执行git命令,<1在当前目录执行git命令
使用方式如下:
> sh git_batch_pull.sh workspace/demo/helloworld 0
> sh git_batch_pull.sh workspace/demo 1
> sh git_batch_pull.sh workspace 2
脚本源码git_batch_pull.sh
#指定git项目的父级目录,遍历目录下的所有工程,批量拉取代码
#参数$1:目录
#参数$2:需要进几次目录执行git命令,<1在当前目录执行git命令
#使用方式如下:
#> sh git_batch_pull.sh workspace/demo/helloworld 0
#> sh git_batch_pull.sh workspace/demo 1
#> sh git_batch_pull.sh workspace 2
#! /bin/bash
function deal_dir(){
if [ 1 -lt $2 ] #是否下处理下一级目录
then
echo "########################################################################"
echo 'parent dir-> level['$2'], path['$1'/'$3']'
echo "------------------------------------------------------------------------"
read_dir $1'/'$3 `expr $2 - 1` $3
echo "########################################################################"
else
echo 'dir-> level['$2'], path['$1'/'$3']'
sh -c 'cd '$1'/'$3' && git pull'
fi
}
function deal_file() {
echo 'file-> level['$2'], path['$1'/'$3']'
}
function read_dir(){
if [ 0 -lt $2 ] #是否下处理下一级目录
then
for file in `ls $1`
do
if [ -d $1'/'$file ] #是否目录
then
deal_dir $1 $2 $file
else
deal_file $1 $2 $file
fi
done
else
echo 'dir-> level['$2'], path['$1 $2']'
sh -c 'cd '$1' && git pull'
fi
}
read_dir $1 $2