Commit 19e3f1a19cf for woocommerce
commit 19e3f1a19cf7f16c6d8027e554bd91934f764593
Author: Faisal Ahammad <faisalahammad24@gmail.com>
Date: Mon Oct 19 18:56:16 2026 +0600
fix: skip trunk push prompt when pushing to a fork (#66277)
The pre-push hook prompted for confirmation on every push of a trunk
branch, even when the destination was a contributor's fork instead of
the canonical woocommerce/woocommerce repo. Contributors syncing their
fork's trunk with upstream hit this prompt on every sync.
Now the hook checks the destination remote URL (passed by git as $2)
and only asks for confirmation when pushing trunk to woocommerce/woocommerce.
Pushes to any other remote go through unprompted.
diff --git a/.husky/pre-push b/.husky/pre-push
index 8df24a0381a..5002aafba58 100755
--- a/.husky/pre-push
+++ b/.husky/pre-push
@@ -1 +1 @@
-./bin/pre-push.sh
+./bin/pre-push.sh "$@"
diff --git a/bin/pre-push.sh b/bin/pre-push.sh
index bbb5e5e661e..642ca5872a7 100755
--- a/bin/pre-push.sh
+++ b/bin/pre-push.sh
@@ -1,8 +1,18 @@
#!/usr/bin/env bash
+# Git passes the remote name as $1 and the remote URL as $2 to the pre-push hook.
+REMOTE_URL="$2"
+
+# Only prompt when pushing to the canonical repo, forks have nothing to protect.
+# Match the repo path only, so SSH host aliases and explicit ports still count as canonical.
+IS_CANONICAL_REMOTE=1
+if [ -n "$REMOTE_URL" ] && ! echo "$REMOTE_URL" | grep -qiE '[:/]woocommerce/woocommerce(\.git)?/?$'; then
+ IS_CANONICAL_REMOTE=0
+fi
+
PROTECTED_BRANCH="trunk"
CURRENT_BRANCH=$(git branch --show-current)
-if [ $PROTECTED_BRANCH = $CURRENT_BRANCH ]; then
+if [ "$PROTECTED_BRANCH" = "$CURRENT_BRANCH" ] && [ "$IS_CANONICAL_REMOTE" = 1 ]; then
if [ "$TERM" = "dumb" ]; then
>&2 echo "Sorry, you are unable to push to $PROTECTED_BRANCH using a GUI client! Please use git CLI."
exit 1