From 773df0e2d7596d84a711914f1cffb4fb5a107c17 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 31 Jan 2017 10:51:46 -0500 Subject: Add pre-commit hook to check whether SetupForDevelopment must re-run Add a version number to the `SetupForDevelopment.sh` script and use a pre-commit hook to check when it changes. --- Utilities/Git/pre-commit | 13 +++++++++++++ Utilities/SetupForDevelopment.sh | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/Utilities/Git/pre-commit b/Utilities/Git/pre-commit index b232ac0..b63ae5e 100755 --- a/Utilities/Git/pre-commit +++ b/Utilities/Git/pre-commit @@ -29,6 +29,19 @@ die 'The following changes add lines too long for our C++ style: Use lines strictly less than '"$line_too_long"' characters in C++ code.' +#----------------------------------------------------------------------------- + +# 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 + #------------------------------------------------------------------------------- if test -z "$HOOKS_ALLOW_KWSYS"; then # Disallow changes to KWSys diff --git a/Utilities/SetupForDevelopment.sh b/Utilities/SetupForDevelopment.sh index 0a9df7e..39152bc 100755 --- a/Utilities/SetupForDevelopment.sh +++ b/Utilities/SetupForDevelopment.sh @@ -11,3 +11,7 @@ Utilities/GitSetup/tips # Rebase master by default git config rebase.stat true git config branch.master.rebase true + +# Record the version of this setup so Git/pre-commit can check it. +SetupForDevelopment_VERSION=1 +git config hooks.SetupForDevelopment ${SetupForDevelopment_VERSION} -- cgit v0.12 From 3288ab0c78057e2388b247d326dc80011488a0bb Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 31 Jan 2017 10:56:35 -0500 Subject: Convert local hook configuration to a Git config file format The `git config` format is cleaner than a bash script and is also supported by our `hooks` branch to specify CMake-specific hooks. --- .hooks-config | 10 ++++++++++ .hooks-config.bash | 9 --------- 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 .hooks-config delete mode 100644 .hooks-config.bash diff --git a/.hooks-config b/.hooks-config new file mode 100644 index 0000000..064371c --- /dev/null +++ b/.hooks-config @@ -0,0 +1,10 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# 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 + commit-msg = Utilities/Git/commit-msg + prepare-commit-msg = Utilities/Git/prepare-commit-msg diff --git a/.hooks-config.bash b/.hooks-config.bash deleted file mode 100644 index ea9342a..0000000 --- a/.hooks-config.bash +++ /dev/null @@ -1,9 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -# 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" -hooks_chain_commit_msg="Utilities/Git/commit-msg" -hooks_chain_prepare_commit_msg="Utilities/Git/prepare-commit-msg" -- cgit v0.12