Initial commit
Initial checkin of an update hook for preventing checkins of large files or archives.
This commit is contained in:
parent
8ba7b7364b
commit
d954f53142
1 changed files with 57 additions and 0 deletions
57
scripts/pkgs-update-hook/update.secondary
Normal file
57
scripts/pkgs-update-hook/update.secondary
Normal file
|
@ -0,0 +1,57 @@
|
|||
#!/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
|
Loading…
Add table
Add a link
Reference in a new issue