Files
sync-branch/sync.sh
T
bot bae9657059
ci / test (push) Successful in 1m1s
初始版本:從 feather-vault 搬出
2026-11-05 02:54:23 +00:00

24 lines
1009 B
Bash
Executable File
Raw Permalink 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
# 把 SYNC_SHA(來源分支 SYNC_SOURCE 的提交)合併進 SYNC_TARGET 並推送;工作目錄是 fetch-depth: 0 的 checkout,origin 可推送
set -euo pipefail
src=${SYNC_SOURCE:?缺少 SYNC_SOURCE}; dst=${SYNC_TARGET:?缺少 SYNC_TARGET}; sha=${SYNC_SHA:?缺少 SYNC_SHA}
if ! git ls-remote --exit-code --heads origin "$dst" >/dev/null; then
echo "目標分支 $dst 不存在,不同步"
exit 0
fi
git fetch --quiet origin "$dst"
if git merge-base --is-ancestor "$sha" "origin/$dst"; then
echo "$dst 已經包含 $src($sha),不需要同步"
exit 0
fi
git config user.name "ci-sync-branch"
git config user.email "ci-sync-branch@users.noreply.invalid"
git checkout -q -B "$dst" "origin/$dst"
if ! git merge --no-edit -m "合併 $src 進 $dst(自動同步 ${sha::7})" "$sha"; then
git merge --abort || true
echo "::error::合併 $src 進 $dst 有衝突,請手動處理"
exit 1
fi
git push origin "HEAD:refs/heads/$dst"
echo "已把 $src($sha)合併進 $dst"