I've stumbled upon git-hooks and been trying to create one to run on Windows. So I've decided upon using batch files to do so because it seemed easy enough.
First, I renamed the pre-commit sample to pre-commit and called my bat steps there:
#!/bin/sh
$(pwd)/git-hooks/hooks/unit_test.bat &&
$(pwd)/git-hooks/hooks/integration_test.bat
The unit_test.bat only shows some messages and runs the unit tests task, but the integration_test.bat prompts the user on if they want to run these tests or not because they are generally slower.
The problem is that the prompt (done with either 'choice' or 'set /p') doesn't get the user input:
- 'set /p' doesn't wait for user input
- 'choice' freezes and doesn't allow any user input
I've tried adding start to call the .bat files but it opens them on another cmd so it makes it impossible to stop the commit.
Files referenced
unit_test.bat
@echo off echo ^> Testes unitários call gradlew testReport || (echo(& echo Testes unitários falharam! Acesse o relatório de testes para conferir.& exit 1))
integration_test.bat
@echo off echo(echo ^> Testes integrados %SystemRoot%\System32\choice.exe /C sn /M "Esses testes geralmente são mais lentos. Quer rodar os testes integrados" if ERRORLEVEL 2 goto nao call gradlew integrationTests || (echo(echo Testes integrados falharam! Acesse o relatório de testes para conferir.) && exit 1) :nao echo(echo Não se esqueça de confirmar que os testes integrados passam antes de fazer o 'git push'!) exit /B