mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
fix(husky): guard against commits/pushes to merged or closed PR branches (#1979)
Pre-commit now checks gh pr state before allowing any commit — exits 1 with a clear message if the branch PR is MERGED or CLOSED, preventing orphaned commits (as happened on PRs #1893, #1898, and #1974). Pre-push: changed 2>/dev/null to 2>&1 so gh errors surface visibly, and added a state echo line so the current PR state is always logged.
This commit is contained in:
@@ -1,2 +1,16 @@
|
||||
BRANCH=$(git branch --show-current)
|
||||
if [ -n "$BRANCH" ] && [ "$BRANCH" != "main" ] && [ "$BRANCH" != "master" ]; then
|
||||
PR_STATE=$(gh pr view "$BRANCH" --json state --jq '.state' 2>/dev/null)
|
||||
if [ "$PR_STATE" = "MERGED" ] || [ "$PR_STATE" = "CLOSED" ]; then
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
echo "ERROR: PR for branch '$BRANCH' is $PR_STATE."
|
||||
echo "Do NOT commit to a merged/closed PR branch — commits will be orphaned."
|
||||
echo "Run: git checkout main && git pull && git checkout -b fix/new-branch"
|
||||
echo "============================================================"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Running Unicode safety check (staged files)..."
|
||||
node scripts/check-unicode-safety.mjs --staged || exit 1
|
||||
|
||||
@@ -7,7 +7,7 @@ fi
|
||||
echo "Checking PR status for current branch..."
|
||||
BRANCH=$(git branch --show-current)
|
||||
if [ -n "$BRANCH" ] && [ "$BRANCH" != "main" ] && [ "$BRANCH" != "master" ]; then
|
||||
PR_STATE=$(gh pr view "$BRANCH" --json state --jq '.state' 2>/dev/null)
|
||||
PR_STATE=$(gh pr view "$BRANCH" --json state --jq '.state' 2>&1)
|
||||
if [ "$PR_STATE" = "MERGED" ] || [ "$PR_STATE" = "CLOSED" ]; then
|
||||
echo ""
|
||||
echo "============================================================"
|
||||
@@ -17,6 +17,7 @@ if [ -n "$BRANCH" ] && [ "$BRANCH" != "main" ] && [ "$BRANCH" != "master" ]; the
|
||||
echo "============================================================"
|
||||
exit 1
|
||||
fi
|
||||
echo " Branch PR state: ${PR_STATE:-unknown}"
|
||||
fi
|
||||
|
||||
echo "Running type check..."
|
||||
|
||||
Reference in New Issue
Block a user