Files
member-platform/scripts/push-backend.sh

45 lines
1.1 KiB
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
set -euo pipefail
if [ $# -lt 1 ]; then
echo "用法: scripts/push-backend.sh \"後端 commit 訊息\" [根目錄 commit 訊息]"
exit 1
fi
SUB_MSG="$1"
ROOT_MSG="${2:-chore: bump backend submodule}"
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
SUB_DIR="$ROOT_DIR/backend"
current_branch="$(git -C "$SUB_DIR" branch --show-current)"
if [ -z "$current_branch" ]; then
echo "backend 目前是 detached HEAD請先執行: cd backend && git checkout master"
exit 1
fi
if [ "$current_branch" != "master" ]; then
echo "backend 目前分支是 $current_branch,建議先切到 master 再執行。"
exit 1
fi
if [ -n "$(git -C "$SUB_DIR" status --porcelain)" ]; then
git -C "$SUB_DIR" add -A
git -C "$SUB_DIR" commit -m "$SUB_MSG"
else
echo "backend 無本地變更,略過 backend commit。"
fi
git -C "$SUB_DIR" push origin master
git -C "$ROOT_DIR" add backend
if ! git -C "$ROOT_DIR" diff --cached --quiet; then
git -C "$ROOT_DIR" commit -m "$ROOT_MSG"
else
echo "根目錄無 submodule pointer 變更,略過根目錄 commit。"
fi
git -C "$ROOT_DIR" push origin master
echo "完成: backend 與根目錄已 push。"