aboutsummaryrefslogtreecommitdiffstats
path: root/.githooks/pre-commit
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2017-12-31 01:08:46 +0100
committerJakub Jirutka <jakub@jirutka.cz>2017-12-31 01:09:51 +0100
commit6b1401bfbcbd476aea75dcd136c1007913daffb1 (patch)
tree30c4a56e9f73fc0b992d6c557f8785b90835368d /.githooks/pre-commit
parent9a8fafdfdf6abbad63d5b26f6fdad386d63fdfa0 (diff)
downloadaports-6b1401bfbcbd476aea75dcd136c1007913daffb1.tar.gz
aports-6b1401bfbcbd476aea75dcd136c1007913daffb1.tar.bz2
aports-6b1401bfbcbd476aea75dcd136c1007913daffb1.tar.xz
githooks: add check for file size into pre-commit hook
Diffstat (limited to '.githooks/pre-commit')
-rwxr-xr-x.githooks/pre-commit30
1 files changed, 26 insertions, 4 deletions
diff --git a/.githooks/pre-commit b/.githooks/pre-commit
index b286691a3d..3901bc09de 100755
--- a/.githooks/pre-commit
+++ b/.githooks/pre-commit
@@ -5,6 +5,10 @@
#
set -eu
+# Maximal allowed size (in bytes) of a file.
+FILE_SIZE_LIMIT=262144 # 256 kiB
+
+
if ! command -v sha512sum >/dev/null; then
# macOS / BSDs (?) don't have sha512sum, but shasum.
alias sha512sum='shasum -a 512'
@@ -14,13 +18,13 @@ error() {
printf '\033[0;31mpre-commit:\033[0m %s\n' "$1" >&2 # red
}
-# Prints paths of created or modified APKBUILDs being committed.
-changed_apkbuilds() {
+# Prints paths of created or modified files being committed.
+changed_files() {
git diff-index \
--name-only \
--cached \
--diff-filter=ACMR HEAD \
- -- '**/APKBUILD'
+ -- "$@"
}
# Prints file names and checksums (in format <SHA-512>:<filename>) of local
@@ -79,7 +83,25 @@ check_local_sources() {
return $status
}
+# Checks if the file ($1) being committed is not bigger than FILE_SIZE_LIMIT.
+check_file_size() {
+ local path="$1"
+ local size
+
+ size=$(git cat-file -s ":$path")
+ if [ $size -gt $FILE_SIZE_LIMIT ]; then
+ local size_kb=$(( size / 1024 ))
-for apkbuild in $(changed_apkbuilds); do
+ error "file \"$path\" is quite big ($(( size / 1024 )) kiB), better to upload it to dev.alpinelinux.org"
+ return 1
+ fi
+}
+
+
+for apkbuild in $(changed_files '**/APKBUILD'); do
check_local_sources "$apkbuild"
done
+
+for path in $(changed_files); do
+ check_file_size "$path"
+done