Add git hook for package comparison

When moving to commit, this hook will automatically fire and check the
current system's installed packages against those explicitly committed
to the repository. If they mismatch it will inform the user.

It will not prevent the commit, but simply add a comment at the top of
the commit messages to remind the user that something is unbalanced
between both. It would be recommended to either check the additional
package into source control, remove it from the current system, or
explicitly add it to ignored packages.
This commit is contained in:
Marty Oehme 2020-02-07 22:31:41 +01:00
parent c7ed986c0e
commit ecbf8409f9
No known key found for this signature in database
GPG key ID: 0CCB0526EFB9611A
4 changed files with 76 additions and 1 deletions

View file

@ -44,6 +44,19 @@ check_consent() {
fi
}
enable_git_hooks() {
if [ "$1" == "false" ]; then
echo "Should we enable git hooks for this repository, so that installed packages are automatically compared when committing? [Y/n]"
read -r no
if [[ "$no" == n* ]]; then
echo "Not changing repository settings."
return
fi
fi
git config --local core.hooksPath .githooks/
echo "Changed repository settings."
}
install() {
unattended=$1
if ! "$unattended"; then
@ -68,6 +81,9 @@ install() {
# -- for some reason stow only works with unqoted var expansion
stow -R ${targets} 2> >(grep -v 'Absolute/relative mismatch between Stow dir' 1>&2)
echo "================== ENABLING GIT REPOSITORY HOOKS =========================="
enable_git_hooks "$unattended"
echo "====================== INSTALLATION FINISHED =============================="
exit 0
}