fun updateHook()

in bunch-cli/src/main/kotlin/org/jetbrains/bunches/hooks/hooks.kt [111:125]


fun updateHook(type: HookType, dotGitPath: File) {
    val hooksDirectory = File(dotGitPath, "hooks")
    val hookPath = File(hooksDirectory, type.hookName)
    if (!hookPath.exists() || !checkHookMarker(hookPath.readText(), type)) {
        exitWithLocalError("No ${type.hookName} hook found")
    }

    val bunchExecutableFile = findExecutableFileFromZip()
        ?: findExecutableFileFromProject()
        ?: exitWithError("Can't find executable file")

    val oldHookPath = hookCodeParams(hookPath.readText()).oldHookPath
    hookPath.writeText(type.getHookCodeTemplate(bunchExecutableFile, oldHookPath, dotGitPath.parentFile))
    println("Successfully updated ${type.hookName} hook")
}