THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
879B

  1. #!/bin/sh
  2. #
  3. # This hook adds prefix "<repo>/<pkgname>: " to the commit message when
  4. # committing changes of a single package.
  5. #
  6. MSG_FILE="$1"
  7. SOURCE="$2"
  8. longest_common_prefix() {
  9. awk -F/ '
  10. (NR == 1) { split($0, prefix); prefix_len = NF }
  11. (NR > 1) {
  12. for (i = 1; i <= prefix_len; i++) {
  13. if (prefix[i] != $i) {
  14. prefix_len = i - 1; break
  15. }
  16. }
  17. }
  18. (prefix_len == 0) { exit }
  19. END {
  20. res = prefix[1]
  21. for (i = 2; i <= prefix_len; i++) {
  22. res = res FS prefix[i]
  23. }
  24. print(res)
  25. }'
  26. }
  27. prepend_msg() {
  28. local prefix="$1"
  29. printf '%s\n%s\n' "$prefix" "$(cat "$MSG_FILE")" > "$MSG_FILE"
  30. }
  31. # Do nothing if message has been given using -m, template, merge etc.
  32. [ -z "$SOURCE" ] || exit 0
  33. lcp=$(git diff-index --name-only --cached HEAD | longest_common_prefix)
  34. case "$lcp" in
  35. [^.]*/*) prepend_msg "$(echo "$lcp" | cut -d/ -f1-2): ";;
  36. esac
  37. exit 0