From bea0a7e38e4ddb83c88b3442f300b6f9184de974 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 2 Apr 2020 12:51:02 -0400 Subject: [PATCH] hooks: add hook chains for development checks and LFS --- .hooks-config | 6 ++++++ Utilities/SetupForDevelopment.sh | 3 +++ Utilities/hooks/pre-commit | 24 ++++++++++++++++++++++++ Utilities/hooks/pre-push | 3 +++ 4 files changed, 36 insertions(+) create mode 100644 .hooks-config create mode 100755 Utilities/hooks/pre-commit create mode 100755 Utilities/hooks/pre-push diff --git a/.hooks-config b/.hooks-config new file mode 100644 index 000000000..5fe63d350 --- /dev/null +++ b/.hooks-config @@ -0,0 +1,6 @@ +# Loaded by .git/hooks/(pre-commit|commit-msg|prepare-commit-msg) +# during git commit after local hooks have been installed. + +[hooks "chain"] + pre-commit = utilities/git/pre-commit + pre-push = utilities/git/pre-push diff --git a/Utilities/SetupForDevelopment.sh b/Utilities/SetupForDevelopment.sh index e2a73c366..720a7d974 100755 --- a/Utilities/SetupForDevelopment.sh +++ b/Utilities/SetupForDevelopment.sh @@ -28,3 +28,6 @@ echo "Set up git gitlab-push" && git config alias.gitlab-sync '!bash Utilities/GitSetup/git-gitlab-sync' && echo "Set up git gitlab-sync" && true + +SetupForDevelopment=1 +git config hooks.SetupForDevelopment ${SetupForDevelopment_VERSION} diff --git a/Utilities/hooks/pre-commit b/Utilities/hooks/pre-commit new file mode 100755 index 000000000..2df9e7620 --- /dev/null +++ b/Utilities/hooks/pre-commit @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +die() { + echo 'pre-commit hook failure' 1>&2 + echo '-----------------------' 1>&2 + echo '' 1>&2 + echo "$@" 1>&2 + exit 1 +} + +#----------------------------------------------------------------------------- + +# Check that development setup is up-to-date. +lastSetupForDevelopment=$(git config --get hooks.SetupForDevelopment || echo 0) +eval $(grep '^SetupForDevelopment_VERSION=' "${BASH_SOURCE%/*}/../SetupForDevelopment.sh") +test -n "$SetupForDevelopment_VERSION" || SetupForDevelopment_VERSION=0 +if test $lastSetupForDevelopment -lt $SetupForDevelopment_VERSION; then + die 'Developer setup in this work tree is out of date. Please re-run + + Utilities/SetupForDevelopment.sh +' +fi diff --git a/Utilities/hooks/pre-push b/Utilities/hooks/pre-push new file mode 100755 index 000000000..e930f484f --- /dev/null +++ b/Utilities/hooks/pre-push @@ -0,0 +1,3 @@ +#!/bin/sh +command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path.\n"; exit 2; } +git lfs pre-push "$@"