dotfiles/private_dot_config/git-hooks/pre-commit.d/executable_02_check.sh
2023-01-18 13:42:14 +01:00

84 lines
2.2 KiB
Bash

#!/bin/bash
checkBash()
{
local file=$1
echo checking for 'version' in $file
now=`date +'%Y-%m-%d %R'`
sed -i "s/^\(#.*\)version: .*/\1version: $now/" $file
sed -i "s/^\(#.*\)Version: .*/\1Version: $now/" $file
git add $file
}
# Set (Last Modified: <date>) in CHANGELOG.md
checkChangelog()
{
local file=$1
echo checking for 'Last Modified' in $file
now=`date +'%Y-%m-%d'`
sed -i "s/\(Last Modified: .*\)/\(Last Modified: $now\)/" $file
git add $file
}
checkConfiguration()
{
local file=$1
echo checking for '# Version:' in $file
now=`date +'%Y-%m-%d %R'`
sed -i "s/# version: .*/# version: $now/" $file
sed -i "s/# Version: .*/# Version: $now/" $file
git add $file
}
checkWhitespace()
{
local file=$1
local myTabs=$(grep -P '\t' $file | wc -l)
if [ $myTabs -ne 0 ]; then
echo -e "\e[31m → multiple Tabs ($myTabs) in $file \e[0m"
exit 42
fi
}
# For Jump Page Index HTML
checkIndexHtml()
{
local file=$1
sed -i "s/DAIMLER \(Version: .*/DAIMLER \(Version: $now/" $file
git add $file
}
for FILE in `exec git diff --cached --name-only --diff-filter=ACMR` ; do
# Fix them!
case $FILE in
*.java)
echo -e "\e[32mchecking @version in $FILE\e[0m"
now=`date +'%d.%m.%Y %R'`
sed -i "s/@version .*/@version $now/" $FILE
checkWhitespace $FILE
git add $FILE
;;
*.sh|*.profile)
checkBash $FILE
;;
CHANGELOG.md)
checkChangelog $FILE
;;
*/template.d/*|*.conf|*/config.properties)
checkConfiguration $FILE
;;
index.html)
echo "checking index.html in $FILE"
checkIndexHtml $FILE
;;
*.*|*/pre-commit)
echo "ignoring $FILE"
;;
*)
checkBash $FILE
;;
esac
done
exit