From 328ee5e65cd273648e296912760ebbe69381deba Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Fri, 29 Dec 2017 00:53:29 +0100 Subject: githooks: fix checksum comparison in pre-commit hook The previous method didn't work for larger files. --- .githooks/pre-commit | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 1960d863ba..b286691a3d 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -57,22 +57,23 @@ check_local_sources() { local apkbuild="$1" local startdir="${apkbuild%/*}" local status=0 - local checksum content filename line sources + local checksum_act checksum_exp content filename line sources sources=$(abuild_local_sources "$apkbuild") for line in $sources; do filename=${line%%:*} - checksum=${line#*:} + checksum_exp=${line#*:} - content=$(git show ":$startdir/$filename" 2>/dev/null) || { + if ! git cat-file -e ":$startdir/$filename" 2>/dev/null; then error "$startdir: missing file \"$filename\"" status=1 continue - } - [ "$(printf '%s\n' "$content" | sha512sum)" = "$checksum -" ] || { + fi + checksum_act=$(git show ":$startdir/$filename" | sha512sum) + if [ "$checksum_act" != "$checksum_exp -" ]; then error "$startdir: bad checksum for file \"$filename\" (hint: run abuild checksum)" status=1 - } + fi done return $status -- cgit v1.2.3