Skip to content
Snippets Groups Projects
pre-commit 678 B
#!/usr/bin/env -S bash -euo pipefail

if git rev-parse --verify HEAD >/dev/null 2>&1; then
	against=HEAD
else
	# Initial commit: diff against an empty tree object
	against=$(git hash-object -t tree /dev/null)
fi

changed_files=$(git diff-index --name-only $against)

for file in $changed_files; do
  if [[ $file =~ \.yml$ ]] && grep -q -E 'skyreach_(system|activation)_key' $file; then
    key=$(grep -E 'skyreach_(system|activation)_key' $file | awk '{print $2}')
    if [ $key != "changeme" ]; then
      echo "error: you are about to commit a secret key in file $file"
      grep -E 'skyreach_(system|activation)_key' $file
      exit 1
    fi
  fi
done

exit 0

# vim:ft=sh