fix(git): block push to merged/closed PR branches in pre-push hook (#1924)

Checks gh pr view <branch> --json state before running any tests.
If MERGED or CLOSED, exits 1 with a clear message and instructions
to branch from origin/main. Prevents orphaned commits like those on
PRs #1893, #1898, #1911, #1921.
This commit is contained in:
Elie Habib
2026-03-20 16:19:18 +04:00
committed by GitHub
parent c658b8eb94
commit c3f43376b7

View File

@@ -4,6 +4,21 @@ if [ ! -d node_modules ]; then
npm install --prefer-offline || exit 1
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)
if [ "$PR_STATE" = "MERGED" ] || [ "$PR_STATE" = "CLOSED" ]; then
echo ""
echo "============================================================"
echo "ERROR: PR for branch '$BRANCH' is $PR_STATE."
echo "Do NOT push 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 type check..."
npm run typecheck || exit 1