45 lines
1.2 KiB
Bash
Executable File
45 lines
1.2 KiB
Bash
Executable File
#!/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。"
|