fedora-infrastructure/scripts/pkgs-update-hook/update.secondary
Jason Tibbitts d954f53142 Initial commit
Initial checkin of an update hook for preventing checkins of large files
or archives.
2011-03-24 13:49:25 -05:00

57 lines
1.6 KiB
Bash

#!/bin/bash
# Maximum file size in bytes
MAX_SIZE=20000
tmp=$(mktemp /tmp/git.update.XXXXXX)
tree=$(mktemp /tmp/git.diff-tree.XXXXXX)
bad_file_found=0
git diff-tree -r "$2" "$3" > $tree
while read old_mode new_mode old_sha1 new_sha1 status name; do
# skip lines showing parent commit
[[ -z "$new_sha1" ]] && continue;
# skip deletions
[[ "$new_sha1" = "0000000000000000000000000000000000000000" ]] && continue
# Skip files named *patch
if [[ "$name" =~ [.]patch$ ]]; then
continue
fi
git cat-file blob $new_sha1 > $tmp
ftype="$((file "$tmp" | awk -F': ' '{print $2}') 2>/dev/null)"
fsize=$(stat -c%s "$tmp")
if [[ $fsize -gt $MAX_SIZE ]]; then
echo "File $name - exceeds maximum permitted size $MAX_SIZE"
bad_file_found=1
fi
# Banned archive types
#echo $ftype
if [[ $ftype =~ "Zip archive" ]]; then
echo "File $name - please upload zip files to the lookaside instead"
bad_file_found=1
fi
if [[ $ftype =~ "compressed data" ]]; then
echo "File $name - please upload compressed files to the lookaside instead"
bad_file_found=1
fi
if [[ $ftype =~ "tar archive" ]]; then
echo "File $name - please upload tarballs to the lookaside instead"
bad_file_found=1
fi
done < $tree
rm -f $tmp
if [[ $bad_file_found -eq 1 ]]; then
echo "===================="
echo "Your commit contained problematic files."
echo "Please see http://fedoraproject.org/wiki/foo for more information."
echo "===================="
fi
exit $bad_file_found