Hooks: Update deny_binary to correctly handle pushes to new repos

Before, the hook would allow pushing binary files to newly created empty
repos. Now we handle and test this in our test suite.
This commit is contained in:
Sebastian Parborg
2026-03-13 18:23:19 +01:00
parent 8322d84db6
commit f0357e8394
5 changed files with 92 additions and 9 deletions

View File

@@ -28,9 +28,17 @@ while read oldrev newrev refname; do
continue
fi
# Set oldrev to HEAD if this is branch creation.
if [ "$oldrev" = "$nullsha" ]; then
oldrev="HEAD"
if [ $(git rev-parse HEAD) = "HEAD" ]; then
# Iterate over all commits if there is no HEAD.
# This happens when the repo has just been initalized
rev_range=${newrev}
else
# Don't iterate over any commits already in the default branch of the repo
rev_range=HEAD..${newrev}
fi
else
rev_range=${oldrev}..${newrev}
fi
# Check for branches and tags, but not pull requests in refs/pull. Otherwise Gitea
@@ -44,7 +52,7 @@ while read oldrev newrev refname; do
fi
# Loop over each commit.
for commit in $(git rev-list --objects ${oldrev}..${newrev} |
for commit in $(git rev-list --objects ${rev_range} |
git cat-file --batch-check='%(objectname) %(objecttype) %(objectsize) %(rest)' | grep commit | awk '{print $1}'); do
# Get list of potentially binary files in this commit