#!/bin/bash
merge_branch() {
target_branch="$1"
source_branch="$2"
commit_message="$3"
echo ">>>>>>>>>>>>>>>>>>>> 切换到 $target_branch 分支并拉取最新代码..."
git checkout "$target_branch"
git pull origin "$target_branch"
echo ">>>>>>>>>>>>>>>>>>>> 合并 $source_branch 到 $target_branch..."
git merge "$source_branch" -m "$commit_message"
if [ $? -ne 0 ]; then
echo ">>>>>>>>>>>>>>>>>>>> 合并 $source_branch 到 $target_branch 时遇到冲突。请解决冲突并继续..."
echo ">>>>>>>>>>>>>>>>>>>> 请手动解决冲突后,继续执行脚本"
exit 1
fi
echo ">>>>>>>>>>>>>>>>>>>> 推送合并后的代码到远程仓库..."
git push origin "$target_branch"
}
echo ">>>>>>>>>>>>>>>>>>>> 切换到 2024_05_ft 分支..."
git checkout 2024_05_ft
git pull origin 2024_05_ft
merge_branch "2024_05_main" "2024_05_ft" "Merge branch '2024_05_ft' into 2024_05_main"
merge_branch "saas_dev" "2024_05_main" "Merge branch '2024_05_main' into saas_dev"
merge_branch "pvt_dev" "2024_05_main" "Merge branch '2024_05_main' into pvt_dev"
if [ "$1" = "--xc" ]; then
echo ">>>>>>>>>>>>>>>>>>>> 合并 pvt_dev 到 xc_dev 分支..."
merge_branch "xc_dev" "pvt_dev" "Merge branch 'pvt_dev' into xc_dev"
fi
echo ">>>>>>>>>>>>>>>>>>>> 回到原始分支..."
git checkout 2024_05_ft