# vim /mnt/d/git.bash
#!/bin/bash
Dirname=$1 #项目目录名称
dest_branch=$2 #需要合并的分支
src_branch=$3 #分支是master或prepare
dir="/mnt/d/shuyuan001"
if [ $# -eq 0 ] || [ $# -eq 1 ] || [ $# -eq 2 ];then
echo -e "\033[31m"\$1"项目目录名称:shuyuan_api"
echo -e "\033[31m"\$2"需要合并的分支:dev18_14"
echo -e "\033[31m"\$3"分支:master或prepare"
echo -e "\033[32m /bin/bash $0 "\$1" "\$2" "\$3""
exit 1
fi
cd ${dir}/${Dirname}
git checkout ${src_branch} >& /dev/null
get_branch=`git branch | grep ${src_branch} | awk '{print $2}'`
if [ "${get_branch}" = "master" ];then
echo -e "\033[33m已经在master分支\033[0m"
git pull
git checkout ${dest_branch} >& /dev/null
if [ $? -eq 0 ];then
echo -e "\033[33mmaster切换${dest_branch}分支成功\033[0m"
git pull
git checkout master
if [ $? -eq 0 ];then
git merge ${dest_branch}
git push origin ${src_branch}
echo -e "\033[33m${dest_branch}分支合并成功\033[0m"
else
echo -e "\033[31m切换prepare分支失败\033[0m"
fi
else
echo -e "\033[31mmaster切换${dest_branch}分支失败\033[0m"
fi
elif [ "${get_branch}" = "prepare" ];then
echo -e "\033[33m已经在prepare分支\033[0m"
git pull
git checkout ${dest_branch} >& /dev/null
if [ $? -eq 0 ];then
echo -e "\033[33mprepare切换${dest_branch}分支成功\033[0m"
git pull
git checkout prepare
if [ $? -eq 0 ];then
git merge ${dest_branch}
git push origin ${src_branch}
echo -e "\033[33m${dest_branch}分支合并成功\033[0m"
else
echo -e "\033[31m切换prepare分支失败\033[0m"
fi
else
echo -e "\033[31mprepare切换${dest_branch}分支失败\033[0m"
fi
else
echo -e "\033[31m切换${src_branch}分支失败\033[0m"
fi