背景
在公司项目中遇到了一个项目的各个子模块在不同git仓库中,于是将所有git仓库目录放到一个子目录下,并写了一个简单的同步脚本。
脚本
#!/usr/bin/env bash
#!/usr/bin/env bash
if test -z "$1"; then
$1 = dev
fi
if test -z "$2"; then
$2 = ./
fi
workPath=$(readlink -f $2)
for file in $workPath/*; do
if test -d ${file}; then
# filePath=$(readlink -f ${file})
cd ${file}
if test -f pom.xml; then
mvn clean &
fi
# check if contains git repository
if test -d .git; then
echo "================update git repository in file: "${file}"================"
# change to target brach
remoteDevBranchName=$(git branch -a | grep $1 | grep origin)
if test -n "$remoteDevBranchName"; then
echo "===