lean4-htt/script/prepare-commit-msg

28 lines
607 B
Bash
Executable file

#!/usr/bin/env bash
set -eo pipefail
# exit on existing commit message
[[ -z "$2" ]] || exit 0
# remove last line "$n files changed [...]"
diff=$(git diff --staged --stat | grep -v '.*.expected.out' | head -n -1)
# take file with most changes
file=$(echo "$diff" | sort -n -k 3 | tail -n 1)
# extract filename
file=$(echo "$file" | cut -f 2 -d' ')
file="${file#'src/'}"
file="${file%.(cpp|h|md|lean)}"
case $file in
tests/*)
type=test
;;
script/*)
type=chore
;;
*)
type=feat
;;
esac
orig=$(cat "$1")
echo "$type($file):" > $1
echo "$orig" >> $1