Files
homepage/tools/finish-feature.sh

30 lines
821 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 在 feature 分支上执行:合并到 main、推送、删除本地和远端分支
# 用法:bash tools/finish-feature.sh
set -euo pipefail
BRANCH=$(git branch --show-current)
if [[ ! "$BRANCH" =~ ^feature/ ]]; then
echo "❌ 当前分支不是 feature/*:${BRANCH}"
exit 1
fi
if ! git diff --quiet || ! git diff --cached --quiet; then
echo "❌ 工作区有未提交改动,先提交或暂存"
exit 1
fi
echo "== 合并 ${BRANCH} → main"
git checkout main
git pull --ff-only origin main
git merge --no-ff "$BRANCH" -m "Merge branch '${BRANCH}'"
git push origin main
echo "== 清理分支 ${BRANCH}"
git branch -d "$BRANCH"
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
git push origin --delete "$BRANCH"
fi
echo "✅ 已合并并清理 ${BRANCH}"