As mentioned in the Git client-side hooks, the prepare-commit-msg
hook is run before the commit message editor is fired up but after the default message is created.
So that would not feed your requirement. It would be better to use a commit-msg
hook.
The commit-msg
hook takes one parameter, which again is the path to a temporary file that contains the commit message written by the developer.
If this script exits non-zero, Git aborts the commit process, so you can use it to validate your project state or commit message before allowing a commit to go through.
After that, it depends on how your script is written: see "How do I prompt the user from within a commit-msg hook?", and this answer in particular:
if you use gitk
or git-gui
you won't be able to prompt because you get an error on the "exec < /dev/tty
" line.
You can replace that by a function defined in your hook bash script
function f_askContinue {
local myQuestion=$1
while true; do
read -p "${myQuestion} " -n 1 -r answer
case $answer in
[Yy]* ) printf "\nOK\n"; break;;
[Nn]* ) printf "\nAbandon\n";
exit;;
* ) printf "\nAnswer with Yes or No.\n";;
esac
done
}
f_askContinue "Do you want to continue ?"
(Adapt that to the logic you want to implement in your control)
That would work from gitk.