dotfiles/.githooks/prepare-commit-msg
Marty Oehme 280fab6ad3
bootstrap: Switch package list to tsv
Package list is now a single tab separated list. That should make
several automations in the future much simpler.

The table is built as follows:
`Name   Description Source  Target`

with one line per package. Source denotes official repositories or AUR,
and target is kept for future potential of creating different
deployments per target automatically (e.g. different package list for
desktop and server, and so on).

There is an updater script `bootstrap/update_package_list.sh` which will
automatically populate the table, removing uninstalled packages, adding
new ones and (making its best attempt to be) keeping the selected
targets as they are.

The git commit hook comparing installed and committed packages has also
been rewritten to use the new table and be a little simpler overall.

Fixes #2.
2022-03-09 11:13:45 +01:00

27 lines
970 B
Bash
Executable file

#!/usr/bin/env bash
COMMIT_MSG_FILE="$1"
COMMIT_SOURCE="$2"
BOOTSTRAPDIR="bootstrap"
pkg_committed="$(cat $(git rev-parse --show-toplevel)/$BOOTSTRAPDIR/packages.tsv | tail +2 | cut -f1 | sort)"
pkg_onsystem=$(pacman -Qqett | grep -v "$(pacman -Qqg base-devel)" | sort)
# 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"))
# if we have no changes, do nothing
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')
else
exit 0
fi
# prepend package changes to message
case $COMMIT_SOURCE in
"" | message, | template,)
msg=$(echo "$text" | cat - "$COMMIT_MSG_FILE")
printf "%s" "$msg" >"$COMMIT_MSG_FILE"
;;
esac