main
1#!/bin/sh
2#set -v -x
3set -e -u -o pipefail
4
5# Redirect output to stderr.
6exec 1>&2
7
8if ! which exiftool > /dev/null; then
9 echo "exiftool is required for git pre-commit hook!"
10 exit 1
11fi
12
13# don't commit photo metadata except colour settings
14git diff-index --cached --diff-filter=A --name-only HEAD | ( grep -Ei '\.(HEIC|jpeg|jpg|tiff|tif|png|webp|avif|jxl)$' || true ) | while read file; do
15 exiftool -all= --icc_profile:all -tagsfromfile @ -colorspacetags $file -o $file.tmp > /dev/null
16 if ! diff $file $file.tmp; then
17 echo "Apparently there is metadata still in $file, aborting!"
18 echo "Try:"
19 echo "exiftool -all= --icc_profile:all -tagsfromfile @ -colorspacetags $file"
20 #rm $file.tmp
21 exit 1
22 fi
23 rm $file.tmp
24done