Skip to content

Instantly share code, notes, and snippets.

@shsteimer
Created August 3, 2022 20:03
Show Gist options
  • Save shsteimer/033d1d56c9310a0370a18445bf961dcc to your computer and use it in GitHub Desktop.
Save shsteimer/033d1d56c9310a0370a18445bf961dcc to your computer and use it in GitHub Desktop.
Pre-Commit hook to prevent modifications to immutable dispatcher files
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi
# Redirect output to stderr.
exec 1>&2
# full paths from the repo root separated by newlines
DISP_IMMUTABLE='dispatcher/src/conf.d/available_vhosts/default.vhost
dispatcher/src/conf.d/dispatcher_vhost.conf
dispatcher/src/conf.d/rewrites/default_rewrite.rules
dispatcher/src/conf.dispatcher.d/available_farms/default.farm
dispatcher/src/conf.dispatcher.d/cache/default_invalidate.any
dispatcher/src/conf.dispatcher.d/cache/default_rules.any
dispatcher/src/conf.dispatcher.d/clientheaders/default_clientheaders.any
dispatcher/src/conf.dispatcher.d/dispatcher.any
dispatcher/src/conf.dispatcher.d/enabled_farms/default.farm
dispatcher/src/conf.dispatcher.d/filters/default_filters.any
dispatcher/src/conf.dispatcher.d/renders/default_renders.any
dispatcher/src/conf.dispatcher.d/virtualhosts/default_virtualhosts.any'
if git diff --cached --name-only $against |
grep --quiet --line-regexp --fixed-strings "$DISP_IMMUTABLE"
then
echo Attempting to modify one or more immutable files. Please revert immutable file changes, or if this is neccessary run git commit --no-verify
exit 1
else
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment