From dc31be5bda3817384e0208b38a905ab8a070196a Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 16 Nov 2010 17:40:16 -0500 Subject: Chain to script configured by "hooks.chain-" Chain the pre-commit, commit-msg, and prepare-commit-msg hooks to locally configured scripts. Interpret relative paths with respect to the working directory where the hooks run (top of work tree). This allows project setup scripts to add project-specific checks for each of these hooks. --- commit-msg | 5 +++++ hooks-chain.bash | 31 +++++++++++++++++++++++++++++++ pre-commit | 5 +++++ prepare-commit-msg | 21 +++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 hooks-chain.bash create mode 100755 prepare-commit-msg diff --git a/commit-msg b/commit-msg index 92a95cd025..7856f1ef57 100755 --- a/commit-msg +++ b/commit-msg @@ -125,3 +125,8 @@ case "$hooks_GerritId" in '') gerrit_advice ;; *) gerrit_error ;; esac + +#----------------------------------------------------------------------------- +# Chain to project-specific hook. +. "$GIT_DIR/hooks/hooks-chain.bash" +hooks_chain commit-msg "$@" diff --git a/hooks-chain.bash b/hooks-chain.bash new file mode 100644 index 0000000000..63c1f4019b --- /dev/null +++ b/hooks-chain.bash @@ -0,0 +1,31 @@ +#============================================================================= +# Copyright 2010 Kitware, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= + +hooks_chain() { + hook="$1" ; shift + chain=$(git config --get hooks.chain-$hook) || return 0 + case "$chain" in + '/'*) prefix="" ;; + '[A-Za-z]:/'*) prefix="" ;; + '.'*) prefix="" ;; + *) prefix="./" ;; + esac + if test -x "$prefix$chain" ; then + exec "$prefix$chain" "$@" + fi +} + +# vim: set filetype=sh tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab : diff --git a/pre-commit b/pre-commit index 15a0151b00..0f710552c8 100755 --- a/pre-commit +++ b/pre-commit @@ -252,4 +252,9 @@ test -z "$bad" || die "$bad" # Style hooks. . "$GIT_DIR/hooks/pre-commit-style" +#----------------------------------------------------------------------------- +# Chain to project-specific hook. +. "$GIT_DIR/hooks/hooks-chain.bash" +hooks_chain pre-commit "$@" + # vim: set filetype=sh tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab : diff --git a/prepare-commit-msg b/prepare-commit-msg new file mode 100755 index 0000000000..505b522d52 --- /dev/null +++ b/prepare-commit-msg @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +#============================================================================= +# Copyright 2010 Kitware, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#============================================================================= + +#----------------------------------------------------------------------------- +# Chain to project-specific hook. +. "$GIT_DIR/hooks/hooks-chain.bash" +hooks_chain prepare-commit-msg "$@" -- cgit v1.2.1