in bunch-cli/src/main/kotlin/org/jetbrains/bunches/hooks/HookCodeTemplate.kt [55:79]
fun preCommitHookTemplate(bunchExecutablePath: File, oldHookPath: String, repoPath: File): String {
return """
#!/bin/bash
$BUNCH_PRE_COMMIT_HOOK_COMMENT_MARKER
$BUNCH_EXECUTABLE_PATH_COMMENT_MARKER '${bunchExecutablePath.absolutePath}'
$OLD_HOOK_PATH_COMMENT_MARKER $oldHookPath
$oldHookPath
exitCode=${'$'}?
if [[ "${'$'}exitCode" -ne 0 ]]
then
exit ${'$'}exitCode
fi
if [[ -t 0 ]] || [[ -t 1 ]] || [[ -t 2 ]]
then
files="${'$'}(git diff --cached --name-only | while read file ; do echo -n "'${'$'}file' "; done)"
eval "'${bunchExecutablePath.absolutePath}' $HOOK_LAUNCH_COMMAND $BUNCH_PRE_COMMIT_CHECK_COMMAND '${repoPath.absolutePath}' ${'$'}files < /dev/tty"
exit $?
else
exit 0
fi
""".trimIndent()
}