Commit ce1b0901 authored by Brad King's avatar Brad King

Delay Git hooks setup until first commit

Install a small .git/hooks/pre-commit script in the source tree at CMake
configuration time instead of telling the user to do it.  When the user
first attempts to commit this bootstrapping hook will trigger and print
instructions to install the real hooks.  This approach allows us to
require local hooks for commit but not for those who just want to build.
parent eb4a548e
......@@ -3,3 +3,4 @@
*.sh crlf=input
newalpha crlf=input
newversion crlf=input
pre-commit crlf=input
#!/bin/sh
echo 'Please initialize your local Git hooks.
Paste the following commands into a shell:
$ cd "'$(pwd)'/.git/hooks"
$ git init
$ git pull .. remotes/origin/hooks
$ cd ../..
See http://www.vtk.org/Wiki/VTK/Git#Hooks for more details.'
exit 1
# Emit a fatal error and inform the user if they have not enabled hooks.
option(VTK_IGNORE_HOOKS "Should the VTK hooks check be ignored?" OFF)
if(DEFINED ENV{DASHBOARD_TEST_FROM_CTEST})
set(VTK_FROM_CTEST TRUE)
endif()
if(NOT VTK_IGNORE_HOOKS AND NOT VTK_FROM_CTEST AND
EXISTS "${VTK_SOURCE_DIR}/.git/config")
if(NOT EXISTS "${VTK_SOURCE_DIR}/.git/hooks/.git/config")
message(FATAL_ERROR
"Please initialize your local Git hooks, paste the following into a shell:
cd \"${VTK_SOURCE_DIR}/.git/hooks\"
git init
git pull .. remotes/origin/hooks
cd ../..
See http://www.vtk.org/Wiki/VTK/Git#Hooks for more details.
If you wish to ignore this check for a build set the CMake cache variable VTK_IGNORE_HOOKS to ON. To ignore this check in all builds either archive your clone, or create the file\n ${VTK_SOURCE_DIR}/.git/hooks/.git/config\nin your source tree.")
# Install a pre-commit hook to bootstrap commit hooks.
if(EXISTS "${VTK_SOURCE_DIR}/.git/config" AND
NOT EXISTS "${VTK_SOURCE_DIR}/.git/hooks/pre-commit")
# Silently ignore the error if the hooks directory is read-only.
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy ${VTK_SOURCE_DIR}/CMake/pre-commit
${VTK_SOURCE_DIR}/.git/hooks/pre-commit
OUTPUT_VARIABLE _output
ERROR_VARIABLE _output
RESULT_VARIABLE _result
)
if(_result AND NOT "${_output}" MATCHES "Error copying file")
message("${_output}")
endif()
endif()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment