mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user