Files @ aa067dbcdc82
Branch filter:

Location: kallithea/kallithea/templates/py/git_pre_receive_hook.py

mads
hooks: move the vcs hook entry points and setup code out of lib

Mercurial hooks are running in a process that already has been initialized, so
they invoke the hooks lib directly. Git hooks are binaries and need a lot of
initialization before they can do the same. Move this extra setup code
elsewhere.

Having this high level code in bin is perhaps also not ideal, but it also
doesn't seem that bad: that is where other command line entry points invoke
make_app.

(It seems like it could be adventageous to somehow use "real" bin commands for
hooks ... but for now we use the home-made templates.)

Note: As a side effect of this change, all git hooks *must* be re-installed
when upgrading.
"""Kallithea Git hook

This hook is installed and maintained by Kallithea. It will be overwritten
by Kallithea - don't customize it manually!

When Kallithea invokes Git, the KALLITHEA_EXTRAS environment variable will
contain additional info like the Kallithea instance and user info that this
hook will use.
"""

import os
import sys

import kallithea.bin.vcs_hooks


# Set output mode on windows to binary for stderr.
# This prevents python (or the windows console) from replacing \n with \r\n.
# Git doesn't display remote output lines that contain \r,
# and therefore without this modification git would display empty lines
# instead of the exception output.
if sys.platform == "win32":
    import msvcrt
    msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY)

KALLITHEA_HOOK_VER = '_TMPL_'
os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER


def main():
    repo_path = os.path.abspath('.')
    git_stdin_lines = sys.stdin.readlines()
    sys.exit(kallithea.bin.vcs_hooks.pre_receive(repo_path, git_stdin_lines))


if __name__ == '__main__':
    main()