#!/bin/bash
cd ..
current_branch=$(git branch --show-current)
target_branch=$(git branch --list develop)
echo "current branch: ${current_branch}"
echo "target branch: ${target_branch}"
commit_message=${current_branch#feature-}
echo "commit message: $commit_message"
git add .
git commit -m "$commit_message"
git push origin "$current_branch"
if [ -z "$target_branch" ]; then
echo "develop本地分支不存在"
git checkout -b develop origin/develop
else
git checkout develop
git pull origin develop:develop
fi
git merge --no-edit "$current_branch"
conflict_num=$(git status --porcelain | grep '^UU' | wc -l)
echo "Conflict number: ${conflict_num}"
if [ "$conflict_num" -gt 0 ]; then
git reset --hard HEAD
echo -e "\033[41m There are conflicts, please solve them! \033[0m"
else
echo -e "\033[42mMerge successfully!\033[0m"
read -p "push it immediately?(y/n):" input
input=$(echo "$input" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [[ $input == "y" ]]; then
git push origin develop
echo -e "\033[42mPush OK!\033[0m"
git checkout "$current_branch"
else
echo -e "\033[41mCancel!\033[0m"
echo -e "\033[41mStay in develop!\033[0m"
exit 1
fi
fi