-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-hooks.py
More file actions
executable file
·47 lines (41 loc) · 1.26 KB
/
Copy pathgit-hooks.py
File metadata and controls
executable file
·47 lines (41 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
import os, sys
import importlib
importlib.reload(sys)
def run_hook(callback, old, new, ref):
if old == "0000000000000000000000000000000000000000":
sys.exit(0)
ret = os.system("git rev-parse -q --verify %s^2 >/dev/null" % new)
if ret == 0:
merge = True
else:
merge = False
sock = os.popen("git rev-list %s..%s" % (old, new))
hashes = sock.readlines()
sock.close()
hashes.reverse()
for i in hashes:
# the second parameter is true, if this is a commit of a
# merge (ie. if it's true, then the sendmail script
# won't send it out, so that only the merge commit is
# mailed after a merge)
last = i == hashes[-1]
callback(i.strip(), merge and not last, ref)
if __name__ == "__main__":
sys.path.append("/etc/git-hooks")
sys.path.append("/usr/share/git-hooks")
from config import config as myconfig
for line in sys.stdin.readlines():
(old, new, ref) = line.split(' ')
name = sys.argv[0].split('/')[1]
if name == "home":
name = "post-receive"
for i in myconfig.enabled_plugins[name]:
s = "%s.%s" % (i, i)
plugin = __import__(s)
for j in s.split(".")[1:]:
plugin = getattr(plugin, j)
try:
run_hook(plugin.callback, old, new, ref.strip())
except Exception as s:
print("Can't run plugin '%s' (%s)" % (i, s))