-
Notifications
You must be signed in to change notification settings - Fork 18
/
prepare-commit-msg.hook
executable file
·35 lines (31 loc) · 1.56 KB
/
prepare-commit-msg.hook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
#
# The hook should exit with non-zero status after issuing
# an appropriate message if it wants to stop the commit.
# Strictly disallow uninitialized Variables
set -u
# Exit if a single command breaks and its failure is not handled accordingly
set -e
old_commit_msg="$(cat "${1}")"
echo -n "" > "${1}"
# Check for new or updated PKGBUILDS
# Use the up-to-date .SRCINFO file to retrieve the variables
# shellcheck disable=SC2046
for path in $(dirname $(git diff --name-only --cached) 2>/dev/null | sort -u); do
if basename -a $(git diff --name-only --cached --diff-filter=A "${path}") 2>/dev/null | sort -u | grep -q "^PKGBUILD$" -; then
# The PKGBUILD is unknown to git, alter the commit message accordignly
pkgbase=$(grep "pkgbase = " "${path}/.SRCINFO" | sed 's/^.*= //')
pkgver=$(grep "pkgver = " "${path}/.SRCINFO" | sed 's/^.*= //')
pkgrel=$(grep "pkgrel = " "${path}/.SRCINFO" | sed 's/^.*= //')
echo -e "addpkg: ${pkgbase} ${pkgver}-${pkgrel}" >> "${1}"
elif basename -a $(git diff --name-only --cached --diff-filter=M "${path}") 2>/dev/null | sort -u | grep -q "^PKGBUILD$" -; then
# The PKGBUILD is known by git
pkgbase=$(grep "pkgbase = " "${path}/.SRCINFO" | sed 's/^.*= //')
pkgver=$(grep "pkgver = " "${path}/.SRCINFO" | sed 's/^.*= //')
pkgrel=$(grep "pkgrel = " "${path}/.SRCINFO" | sed 's/^.*= //')
echo -e "upgpkg: ${pkgbase} ${pkgver}-${pkgrel}" >> "${1}"
## If the pkgrel is "1", assume a new release
#[[ "${pkgrel}" = "1" && $(type -t pkgver) != "function" ]] && echo -e "new release" >> "${1}"
fi
done
echo "${old_commit_msg}" >> "${1}"