2022-03-09 10:13:45 +00:00
#!/usr/bin/env bash
2020-02-07 21:31:41 +00:00
COMMIT_MSG_FILE="$1"
COMMIT_SOURCE="$2"
2020-02-11 09:33:18 +00:00
BOOTSTRAPDIR="bootstrap"
2023-01-16 17:47:47 +00:00
pkg_committed="$(cat "$(git rev-parse --show-toplevel)"/$BOOTSTRAPDIR/packages*.tsv | grep -v -e '^Name Description Source Target' | cut -f1 | sort)"
2022-03-09 10:13:45 +00:00
pkg_onsystem=$(pacman -Qqett | grep -v "$(pacman -Qqg base-devel)" | sort)
2020-02-07 21:31:41 +00:00
2022-03-09 10:13:45 +00:00
# get files only in repo, and only on machine
only_committed=$(comm -23 <(echo "$pkg_committed") <(echo "$pkg_onsystem"))
only_onsystem=$(comm -13 <(echo "$pkg_committed") <(echo "$pkg_onsystem"))
2020-02-07 21:31:41 +00:00
# if we have no changes, do nothing
2022-03-09 10:13:45 +00:00
if [ -n "$only_onsystem" ] || [ -n "$only_committed" ]; then
text=$(printf "\-- PACKAGE CHANGES --\nPackages on machine but not committed:\n%s\n\nPackages committed but not on machine:\n%s\n" "$only_onsystem" "$only_committed" | sed 's/^/# /gm')
2020-02-07 21:31:41 +00:00
else
2022-03-09 10:13:45 +00:00
exit 0
2020-02-07 21:31:41 +00:00
fi
# prepend package changes to message
case $COMMIT_SOURCE in
"" | message, | template,)
2022-03-09 10:13:45 +00:00
msg=$(echo "$text" | cat - "$COMMIT_MSG_FILE")
printf "%s" "$msg" >"$COMMIT_MSG_FILE"
;;
2020-02-07 21:31:41 +00:00
esac