您的位置:首页 > 运维架构 > Shell

【SHELL】批量下载GIT代码

2016-06-02 19:10 477 查看
现在下载代码由SVN更换成GIT,代码仓库路径也从原来的一个变为多个,路径较多,记忆复杂,手工处理较慢。那有没有一种办法可以简单、方便处理呢?

当然有,这里将介绍我今天使用shell处理的方法。

已知:

1、输入:有类似如下的代码路径:git@example.com:framework/app_manager.git

2、输出:将所列出的代码路径全部下载到指定的文件夹下

以下为SHELL代码:

#!/bin/sh

#输入:git@example.com:framework/app_manager.git
#输出:app_manager
GetGitRepsName()
{
#echo "git@example.com:framework/app_manager.git"|sed 's;^.*\/\(.*\)\.git;\1;g'

#这里提供了两种方法去找到app_manager
#gname=`echo $1 | cut -d / -f 2 | cut -d . -f1`
gname=`echo $1 |sed 's;^.*\/\(.*\)\.git;\1;g'`
echo $gname
}

DownloadGitCode()
{
echo "processing : $1"
git clone $1

echo "get target dir"
dirname=`GetGitRepsName $1`
echo "$dirname"

cd $dirname
pwd
#忽略权限检查,这是为什么要获取dirname的原因
git config --add core.filemode false
cd ..
pwd
echo
}

target_dir=default_git
if [ $# -eq 1 ];then
target_dir=$1
fi

echo "create target folder:$target_dir"
mkdir -p $target_dir
rm -rf $target_dir/*
cd $target_dir

#将所需要的权限放到数组中,**注意‘\’前有一个空格**
GIT_LIST_ARRAY=(\
"git@example.com:framework/app_manager.git" \
"git@example.com:framework/common_lib.git" \
"git@example.com:framework/flash_manager.git" \
"git@example.com:framework/javavm.git" \
"git@example.com:player/player.git" \
"git@example.com:player/pvr.git" \
"git@example.com:player/usb_manager.git" \
"git@example.com:dtv/resource_manager.git" \
)

#遍历数组,逐步处理
for gg in ${GIT_LIST_ARRAY[@]}
do
echo "input:$gg"
DownloadGitCode $gg
done

cd ..


大功告成!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  git shell