Gittyup/setup-env.sh
Michael Werle 16276638df build: add configuration for pre-commit hook
Adding a configuration to invoke clang-format v13 on all modified files
as part of the commit process, and a new script file `setup-env.sh` to
manage installing the pre-commit hook.

The hook is installed using a local python venv to ensure the correct
version of clang-format is used. This approach also enables the hook to
be installed on any platform which supports python although the setup
script is limited to platforms which support bash.
2023-08-31 09:43:16 +09:00

45 lines
904 B
Bash
Executable File

#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
cd "`dirname "$0"`"
PRE_COMMIT=${SCRIPT_DIR}/.venv/bin/pre-commit
pre_commit() {
# Set up pre-commit hook
if [ ! -f "${PRE_COMMIT}" ]; then
pushd ${SCRIPT_DIR}
python3 -m venv .venv
.venv/bin/pip install pre-commit
popd
fi
${PRE_COMMIT} install
}
remove_pre_commt() {
if [ -f "${PRE_COMMIT}" ]; then
${PRE_COMMIT} uninstall
fi
}
if [ $# -eq 0 ]; then
set -- --help
fi
for arg in "$@"; do
case $arg in
pre_commit | pre-commit | install_pre_commit | install-pre-commit)
pre_commit
;;
remove_pre_commit | remove-pre-commit | uninstall_pre_commit | uninstall-pre-commit)
remove_pre_commit
;;
*)
echo "USAGE $0 [commands]"
echo " Commands:"
echo " install-pre-commit - installs pre-commit hooks"
echo " uninstall-pre-commit - removes pre-commit hooks"
;;
esac
done