分享一个linux下svn合并脚本
#!/bin/bash
# svn合并脚本 www.zhishiwu.com
# svn版本库地址
BRANCHES_URL=svn://xxx;
# 版本号
version=$1
if [[ $# == 0 ]]; then
usage;
exit;
fi
if [ $? -ne 0 ]; then
echo '版本号必须是数值'
exit
fi
echo '--------------------------------------[开始]--------------------------------------'
# 把要执行动作和对应文件的svn分支路径记录到临时文件中
svn log -r $version -qv $BRANCHES_URL | grep / | awk "{print /$1/$2}" > /tmp/svn_merge_info
i=1
for f in `cat /tmp/svn_merge_info`
do
# 获取执行的动作类型
svn_cmd=`expr substr $f 1 1`
f=`echo $f | sed -e "s/^.//"`
# 获取文件路径 如:/js/test.js (文件分支路如径:/branches/master/js/test.js | /trunk/js/test.js)
local_f=`echo $f | sed -e "s///branches//[^/]*//" | sed -e "s///trunk//"`
case $svn_cmd in
A)
tmp="svn copy -r $version ${BRANCHES_URL}$f .$local_f"
;;
M)
tmp="svn merge -r $((version-1)):$version --ignore-ancestry $BRANCHES_URL$f .$local_f"
;;
D)
tmp="svn del .$local_f"
;;
*)
echo "暂不支持的命令"
exit
;;
esac
echo ''
echo "执行命令:$tmp"
echo ''
echo "结果:"
ttmp=`$tmp`
result=$?
echo $ttmp
echo ''
echo "----------------------------------------$i----------------------------------------"
i=`expr $i + 1`
done
# 获取分支名称
tmp_branche=`svn log $BRANCHES_URL -r $version -qv | tail -n 2 | head -n 1 | sed -r -e "s/.*branches//([^/]*).*//1/"`
branche=$tmp_branche
svn commit -m "从$branche分支的$version版本合并,并自动提交"
echo '--------------------------------------[结束]--------------------------------------'