048a18ad71
Get the githooks from alpine, with the following changes: * Make it possible to parse the additionally nested "device" folder with the exceptions mentioned in our COMMITSTYLE * Ignore "device/*" as a possible prefix for the commit * Replace abuild references with pmbootstrap Relates #2055 [ci:skip-build]: already built successfully in CI
49 lines
1.1 KiB
Bash
Executable file
49 lines
1.1 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# This hook adds prefix "<repo>/<pkgname>: " to the commit message when
|
|
# committing changes of a single package.
|
|
#
|
|
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)
|
|
|
|
case "$lcp" in
|
|
device/*/*) prepend_msg "$(echo "$lcp" | cut -d/ -f3): ";;
|
|
# Multiple packages touched for same device category
|
|
# More logic could be added to detect if they all belong to same device
|
|
device/*) ;;
|
|
[^.]*/*) prepend_msg "$(echo "$lcp" | cut -d/ -f1-2): ";;
|
|
esac
|
|
|
|
exit 0
|