Changeset - f72ead70a22f
[Not reviewed]
default
0 2 0
domruf - 8 years ago 2017-11-29 20:17:02
dominikruf@gmail.com
Grafted from: c9b91e178a30
hook: the git hooks should exit with the return value of the handlers

Like with mercurial hooks, returning a non-zero value means abort the operation
(if possible). So, if for example a hook returns a non-zero value to abort an
unauthorized push, the git hook script needs to exit with that value.
2 files changed with 2 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/config/post_receive_tmpl.py
Show inline comments
 
import os
 
import sys
 

	
 
# 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 displayes 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
 
from kallithea.lib.hooks import handle_git_post_receive as _handler
 

	
 

	
 
def main():
 
    repo_path = os.path.abspath('.')
 
    git_stdin_lines = sys.stdin.readlines()
 
    # os.environ is modified here by a subprocess call that
 
    # runs git and later git executes this hook.
 
    # Environ gets some additional info from kallithea system
 
    # like IP or username from basic-auth
 
    _handler(repo_path, git_stdin_lines, os.environ)
 
    sys.exit(0)
 
    sys.exit(_handler(repo_path, git_stdin_lines, os.environ))
 

	
 

	
 
if __name__ == '__main__':
 
    main()
kallithea/config/pre_receive_tmpl.py
Show inline comments
 
import os
 
import sys
 

	
 
# 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 displayes 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
 
from kallithea.lib.hooks import handle_git_pre_receive as _handler
 

	
 

	
 
def main():
 
    repo_path = os.path.abspath('.')
 
    git_stdin_lines = sys.stdin.readlines()
 
    # os.environ is modified here by a subprocess call that
 
    # runs git and later git executes this hook.
 
    # Environ gets some additional info from kallithea system
 
    # like IP or username from basic-auth
 
    _handler(repo_path, git_stdin_lines, os.environ)
 
    sys.exit(0)
 
    sys.exit(_handler(repo_path, git_stdin_lines, os.environ))
 

	
 

	
 
if __name__ == '__main__':
 
    main()
0 comments (0 inline, 0 general)