commit 7b577e83c246bfb431e4ba0bda8e7913db236050
parent 77f561f96bedc40e6d96305c0ec66fb953148b7f
Author: Chris Bracken <chris@bracken.jp>
Date: Thu, 18 Jun 2026 12:26:33 +0900
Only trigger force-push handling for default branch
Previously we triggered force-push handling for changes to any branch.
We now do it only for the default branch (master or main).
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/post-receive.d/gout b/post-receive.d/gout
@@ -15,6 +15,9 @@ repo_dir=$(pwd)
# This is an optimisation to avoid regenerating all pages on each push.
cachefile="${repo_dir}/.htmlcache"
+# The default branch of the repository.
+default_branch=$(git symbolic-ref HEAD 2>/dev/null || echo "refs/heads/main")
+
# The directory under which all repos are located.
# Repos under this directory will be added to the repo index page.
repos_root=$(dirname "$repo_dir")
@@ -25,13 +28,16 @@ repo_name=$(basename "$repo_dir" '.git')
# Detect --force pushes.
cd "${repo_dir}" || exit 1
force=0
-while read -r old new _; do
+while read -r old new ref; do
+ # Ignore force pushes to non-default branches.
+ [ "${ref}" = "${default_branch}" ] || continue
+
[ "${old}" = "0000000000000000000000000000000000000000" ] && continue
[ "${new}" = "0000000000000000000000000000000000000000" ] && continue
hasrevs=$(git rev-list "$old" "^$new" | sed 1q)
if [ -n "$hasrevs" ]; then
- echo "[gout] Force push detected: cleaning cache"
+ echo "[gout] Force push detected on ${ref}: cleaning cache"
force=1
break
fi