dotfiles/.githooks/prepare-commit-msg
Marty Oehme 60b89b6d30
githook: Fix showing pkgs in commit message
Quick fix to show difference in committed and installed
packages in the commit editor window again.
Due to Arch moving the base-devel package from a group
to a meta-package we can not just remove all packages
that are in the group anymore - it will simply error
out instead. This removes the check and thus provides
a quick and dirty fix for the time being.
2023-06-07 10:29:25 +02:00

27 lines
972 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 | grep -v -e '^Name Description Source Target' | cut -f1 | sort)"
pkg_onsystem=$(pacman -Qqett | 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