autogenerar mensaje de commit
All checks were successful
repro-run Corre repro-run.json

This commit is contained in:
Cat /dev/Nulo 2023-02-08 18:05:50 -03:00
parent 63f8711ab1
commit 538ac08e3e

48
.githooks/prepare-commit-msg Executable file
View file

@ -0,0 +1,48 @@
#!/bin/sh
#
# This hook adds prefix "<article name>: " to the commit message when
# committing changes of a single article.
#
# Robado de alpine/aports
#
MSG_FILE="$1"
SOURCE="$2"
longest_common_prefix() {
awk -F/ '
(NR == 1) { split($0, prefix); prefix_len = NF }
(NR > 1) {
for (i = 1; i <= prefix_len; i++) {
if (prefix[i] != $i) {
prefix_len = i - 1; break
}
}
}
(prefix_len == 0) { exit }
END {
res = prefix[1]
for (i = 2; i <= prefix_len; i++) {
res = res FS prefix[i]
}
print(res)
}'
}
prepend_msg() {
local prefix="$1"
printf '%s\n%s\n' "$prefix" "$(cat "$MSG_FILE")" > "$MSG_FILE"
}
# Do nothing if message has been given using -m, template, merge etc.
[ -z "$SOURCE" ] || exit 0
lcp=$(git diff-index --name-only --cached HEAD | longest_common_prefix)
echo "$lcp"
case "$lcp" in
[^.]*) prepend_msg "${lcp%.*}: ";;
esac
exit 0