fix(hooks): allow pushing feature branches when on main
swadhinbiswas committed 2 months ago
00f02c9
1 parent 3ca41d0
commit 00f02c9
1 file changed
+5 -3
Showing 1 changed file+5-3
▼.githooks/pre-push
+5-3
| @@ -9,8 +9,11 @@ set -e | ||
9 | 9 | |
10 | 10 | BLOCKED=0 |
11 | 11 | |
12 | +HAS_STDIN=0 | |
13 | + | |
12 | 14 | # Read stdin passed by git push: <local_ref> <local_sha> <remote_ref> <remote_sha> |
13 | 15 | while read -r local_ref local_sha remote_ref remote_sha; do |
16 | + HAS_STDIN=1 | |
14 | 17 | if [ "$remote_ref" = "refs/heads/main" ] || [ "$remote_ref" = "refs/heads/master" ]; then |
15 | 18 | BLOCKED=1 |
16 | 19 | TARGET_REF="$remote_ref" |
| @@ -18,11 +21,10 @@ while read -r local_ref local_sha remote_ref remote_sha; do | ||
18 | 21 | fi |
19 | 22 | done |
20 | 23 | |
21 | -# Fallback for invocations where stdin might not provide refs | |
22 | -if [ "$BLOCKED" -eq 0 ]; then | |
24 | +# Fallback only if no refs were passed via stdin | |
25 | +if [ "$HAS_STDIN" -eq 0 ] && [ "$BLOCKED" -eq 0 ]; then | |
23 | 26 | CURRENT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null || echo "") |
24 | 27 | if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "master" ]; then |
25 | - # Check if remote target is default | |
26 | 28 | BLOCKED=1 |
27 | 29 | TARGET_REF="refs/heads/$CURRENT_BRANCH" |
28 | 30 | fi |
29 | 31 | |