#!/bin/bash
# [Usage-Example] : ./cvi_manifest/repo_clone.sh --gitclone subtree.xml
# [Usage-Example] : ./cvi_manifest/repo_clone.sh --gitpull subtree.xml
# [Usage-Example] : ./cvi_manifest/repo_clone.sh --gitclone subtree.xml --normal
# [Usage-Example] : ./cvi_manifest/repo_clone.sh --gitclone subtree.xml --reproduce git_version_2023-08-18.txt
function printusage {
echo "Usage: $0 arg1 arg2 [arg3] [arg4] [arg5 arg6]"
echo "arg1: --gitclone or --gitpull(DEFAULT: git clone)"
echo "arg2: xxx.xml"
echo "arg3: --normal(DEFAULT: clone single branch)"
echo "arg4: --reproduce"
echo "arg5: git_version.txt"
}
# 判断传参数目是否合法
if [[ $# -lt 2 ]]; then
printusage
exit 1
fi
# 获取 User Name
function get_user_name {
USERNAME=$(git config --global user.name)
}
get_user_name
# git clone enable
DOWNLOAD=0
# normal clone enable
NORMAL=0
# reproduce enable
REPRODUCE=0
# 传入参数并赋值
while [[ $# -gt 0 ]]; do
case $1 in
--gitclone)
shift
dir=$1
REMOTE_URL=$(grep -o '' ${dir} | sed 's/.*fetch="\([^"]*\)".*/\1/' | sed "s/ssh:\/\/\(.*\)/ssh:\/\/$USERNAME@\1/")
shift
;;
--gitpull)
shift
dir=$1
DOWNLOAD=1
shift
;;
--normal)
NORMAL=1
shift
;;
--reproduce)
shift
txt=$1
REPRODUCE=1
shift
;;
*)
printusage
exit 1
;;
esac
done
# 设置全局变量
REMOTE_NAME=$(grep -o '' ${dir} | sed 's/.*name="\([^"]*\)".*/\1/')
DEFAULT_REVISION=$(grep -o '' ${dir} | sed 's/.*revision="\([^"]*\)".*/\1/')
PARAMETERS="--single-branch --depth 200"
# 获取xml文件中所有的project name
repo_list=$(grep -o '