|
@@ -160,3 +160,43 @@ class CommitMsgShellHook(ShellHook):
|
|
|
|
|
|
ShellHook.__init__(self, 'commit-msg', filepath, 1,
|
|
|
prepare_msg, clean_msg, controldir)
|
|
|
+
|
|
|
+
|
|
|
+class PostReceiveShellHook(ShellHook):
|
|
|
+ """post-receive shell hook"""
|
|
|
+
|
|
|
+ def __init__(self, controldir):
|
|
|
+ self.controldir = controldir
|
|
|
+ filepath = os.path.join(controldir, 'hooks', 'post-receive')
|
|
|
+ ShellHook.__init__(self, 'post-receive', filepath, 0)
|
|
|
+
|
|
|
+ def execute(self, client_refs):
|
|
|
+ # do nothing if the script doesn't exist
|
|
|
+ if not os.path.exists(self.filepath):
|
|
|
+ return None
|
|
|
+
|
|
|
+ try:
|
|
|
+ env = os.environ.copy()
|
|
|
+ env['GIT_DIR'] = self.controldir
|
|
|
+
|
|
|
+ p = subprocess.Popen(
|
|
|
+ self.filepath,
|
|
|
+ stdin=subprocess.PIPE,
|
|
|
+ stdout=subprocess.PIPE,
|
|
|
+ stderr=subprocess.PIPE,
|
|
|
+ env=env
|
|
|
+ )
|
|
|
+
|
|
|
+ # client_refs is a list of (oldsha, newsha, ref)
|
|
|
+ in_data = '\n'.join([' '.join(ref) for ref in client_refs])
|
|
|
+
|
|
|
+ out_data, err_data = p.communicate(in_data)
|
|
|
+
|
|
|
+ if (p.returncode != 0) or err_data:
|
|
|
+ err_fmt = "post-receive exit code: %d\n" \
|
|
|
+ + "stdout:\n%s\nstderr:\n%s"
|
|
|
+ err_msg = err_fmt % (p.returncode, out_data, err_data)
|
|
|
+ raise HookError(err_msg)
|
|
|
+ return out_data
|
|
|
+ except OSError as err:
|
|
|
+ raise HookError(repr(err))
|