diff --git a/scripts/push-backend.sh b/scripts/push-backend.sh new file mode 100755 index 0000000..babc00e --- /dev/null +++ b/scripts/push-backend.sh @@ -0,0 +1,44 @@ +#!/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。" diff --git a/scripts/push-frontend.sh b/scripts/push-frontend.sh new file mode 100755 index 0000000..2d91c0a --- /dev/null +++ b/scripts/push-frontend.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ $# -lt 1 ]; then + echo "用法: scripts/push-frontend.sh \"前端 commit 訊息\" [根目錄 commit 訊息]" + exit 1 +fi + +SUB_MSG="$1" +ROOT_MSG="${2:-chore: bump frontend submodule}" + +ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +SUB_DIR="$ROOT_DIR/frontend" + +current_branch="$(git -C "$SUB_DIR" branch --show-current)" +if [ -z "$current_branch" ]; then + echo "frontend 目前是 detached HEAD,請先執行: cd frontend && git checkout master" + exit 1 +fi + +if [ "$current_branch" != "master" ]; then + echo "frontend 目前分支是 $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 "frontend 無本地變更,略過 frontend commit。" +fi + +git -C "$SUB_DIR" push origin master + +git -C "$ROOT_DIR" add frontend +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 "完成: frontend 與根目錄已 push。"