Skip to content
Snippets Groups Projects
Commit dc31be5b authored by Brad King's avatar Brad King
Browse files

Chain to script configured by "hooks.chain-<hook>"

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.
parent 2dbbb6ff
No related branches found
No related tags found
No related merge requests found
......@@ -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 "$@"
#=============================================================================
# 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 :
......@@ -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 :
#!/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 "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment