Rainytoken/scripts/sync-upstream.sh

45 lines
1.8 KiB
Bash
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
# ═══════════════════════════════════════════════════════════════
# 一键同步上游 Rainytoken 更新到二开分支
# 用法: ./scripts/sync-upstream.sh [分支名] (默认 dev)
# 流程: fetch origin/main → checkout dev → rebase → assembleDebug
# ═══════════════════════════════════════════════════════════════
set -uo pipefail
cd "$(dirname "$0")/.."
BRANCH="${1:-dev}"
REMOTE="origin"
echo "== [1/5] fetch 上游 main =="
git -c http.proxy= -c https.proxy= fetch "$REMOTE" main || { echo "!! fetch 失败(检查网络/代理)"; exit 1; }
echo "== [2/5] 确保分支 $BRANCH 存在并切过去 =="
if ! git show-ref --verify --quiet "refs/heads/$BRANCH"; then
echo "!! 本地分支 $BRANCH 不存在。若二开工作区尚未提交,请先手动 commit 到 $BRANCH。"
exit 1
fi
git checkout "$BRANCH" || exit 1
echo "== [3/5] rebase 到 origin/main =="
if ! git rebase origin/main; then
echo ""
echo "!! 存在冲突。解决方式:"
echo " 1) 打开冲突文件手动解决(参考 docs/UPSTREAM-SYNC.md §3 已知冲突面)"
echo " 2) git add <冲突文件>"
echo " 3) git rebase --continue"
exit 1
fi
echo "== [4/5] 编译验证 =="
if command -v cmd >/dev/null 2>&1; then
CI=true ./gradlew.bat :app:assembleDebug || { echo "!! 编译失败"; exit 1; }
else
CI=true ./gradlew :app:assembleDebug || { echo "!! 编译失败"; exit 1; }
fi
echo "== [5/5] 完成。最近 5 条提交: =="
git log --oneline -5
echo ""
echo "✅ 同步完成。如需推送手机验证:"
echo " adb install -r app/build/outputs/apk/debug/app-debug.apk"