GIT批量拉取代码shell脚本

描述

指定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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值