githooks/prepare-commit-msg: refactor case...esac

Part-of: https://gitlab.postmarketos.org/postmarketos/pmaports/-/merge_requests/6348
This commit is contained in:
Oliver Smith 2025-03-23 14:13:21 +01:00
parent b8866555b2
commit d203541889
No known key found for this signature in database
GPG key ID: BB8C8A81C6452A88

View file

@ -37,13 +37,24 @@ prepend_msg() {
[ -z "$SOURCE" ] || exit 0
lcp=$(git diff-index --name-only --cached HEAD | longest_common_prefix)
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): ";;
device/*/*)
prefix="$(echo "$lcp" | cut -d/ -f3)"
;;
device/*)
# Multiple packages touched for same device category. More
# logic could be added to detect if they all belong to same
# device.
;;
[^.]*/*)
prefix="$(echo "$lcp" | cut -d/ -f1-2)"
;;
esac
if [ -n "$prefix" ]; then
prepend_msg "$prefix: "
fi
exit 0