修复 pubspbec.lock 文件编译的时候被修改的 bug,必须要保持锁定,除非主动升级
This commit is contained in:
@@ -47,6 +47,7 @@ if [ "$FORMAT" = "aab" ]; then
|
||||
cd "$APP_DIR"
|
||||
flutter build appbundle \
|
||||
--release \
|
||||
--no-pub \
|
||||
--dart-define-from-file=config/config.json \
|
||||
--split-debug-info="$DEBUG_INFO_DIR" \
|
||||
--obfuscate
|
||||
@@ -57,6 +58,7 @@ else
|
||||
cd "$APP_DIR"
|
||||
flutter build apk \
|
||||
--release \
|
||||
--no-pub \
|
||||
--dart-define-from-file=config/config.json \
|
||||
--split-debug-info="$DEBUG_INFO_DIR" \
|
||||
--obfuscate
|
||||
|
||||
@@ -41,6 +41,7 @@ cd "$APP_DIR"
|
||||
|
||||
flutter build ipa \
|
||||
--release \
|
||||
--no-pub \
|
||||
--dart-define-from-file=config/config.json \
|
||||
--split-debug-info="$DEBUG_INFO_DIR" \
|
||||
--obfuscate
|
||||
|
||||
@@ -37,6 +37,7 @@ cd "$APP_DIR"
|
||||
|
||||
flutter build macos \
|
||||
--release \
|
||||
--no-pub \
|
||||
--dart-define-from-file=config/config.json \
|
||||
--split-debug-info="$DEBUG_INFO_DIR" \
|
||||
--obfuscate
|
||||
|
||||
@@ -39,6 +39,7 @@ cd "$APP_DIR"
|
||||
|
||||
flutter build windows \
|
||||
--release \
|
||||
--no-pub \
|
||||
--dart-define-from-file=config/config.json \
|
||||
--split-debug-info="$DEBUG_INFO_DIR" \
|
||||
--obfuscate
|
||||
|
||||
60
scripts/pre-commit
Normal file
60
scripts/pre-commit
Normal file
@@ -0,0 +1,60 @@
|
||||
#!/bin/bash
|
||||
# Git pre-commit hook:提交前自动 format,analyze 有 error 则拦截提交
|
||||
#
|
||||
# 安装:bash scripts/setup.sh(setup.sh 自动把本文件复制到 .git/hooks/pre-commit)
|
||||
# 手动安装:cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(git rev-parse --show-toplevel)"
|
||||
DART="$(command -v dart 2>/dev/null || echo "")"
|
||||
|
||||
if [[ -z "$DART" ]]; then
|
||||
echo "[pre-commit] dart not found, skipping checks."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ── pubspec.lock 保护 ────────────────────────────────────────────────────────
|
||||
# flutter run / flutter build 会在未经授权的情况下触发 pub get 并修改 lock。
|
||||
# 规则:lock 有未暂存的改动(意外修改)→ 自动还原;
|
||||
# 开发者主动 git add pubspec.lock 后(暂存)→ 正常放行。
|
||||
LOCK_UNSTAGED=$(git diff --name-only pubspec.lock 2>/dev/null || true)
|
||||
LOCK_STAGED=$(git diff --cached --name-only pubspec.lock 2>/dev/null || true)
|
||||
|
||||
if [[ -n "$LOCK_UNSTAGED" && -z "$LOCK_STAGED" ]]; then
|
||||
git checkout HEAD -- pubspec.lock
|
||||
echo "[pre-commit] pubspec.lock was auto-modified by flutter, restored to HEAD."
|
||||
echo " To intentionally update: run 'dart pub get' or 'dart pub upgrade',"
|
||||
echo " then 'git add pubspec.lock' before committing."
|
||||
fi
|
||||
|
||||
# ── dart format + analyze ────────────────────────────────────────────────────
|
||||
STAGED_DART=$(git diff --cached --name-only --diff-filter=ACM | grep '\.dart$' || true)
|
||||
|
||||
if [[ -z "$STAGED_DART" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "[pre-commit] formatting staged dart files..."
|
||||
echo "$STAGED_DART" | xargs dart format --line-length=80
|
||||
echo "$STAGED_DART" | xargs git add
|
||||
|
||||
echo "[pre-commit] running dart analyze..."
|
||||
cd "$ROOT_DIR"
|
||||
|
||||
ANALYZE_OUTPUT=$(dart analyze 2>&1)
|
||||
|
||||
if echo "$ANALYZE_OUTPUT" | grep -q "^ error"; then
|
||||
echo "[pre-commit] dart analyze found errors, commit blocked."
|
||||
echo "$ANALYZE_OUTPUT" | grep "^ error"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if echo "$ANALYZE_OUTPUT" | grep -q "^ warning"; then
|
||||
echo "[pre-commit] dart analyze found warnings, commit blocked."
|
||||
echo "$ANALYZE_OUTPUT" | grep "^ warning"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "[pre-commit] all checks passed."
|
||||
exit 0
|
||||
Reference in New Issue
Block a user