split out version functions; add libtool_2_2 check
[platform/upstream/gst-common.git] / hooks / pre-receive.hook
1 #!/usr/bin/env python
2 import sys
3 import os
4 import subprocess
5
6 # This server-side pre-receive hook is to be put and activated in all modules
7 # that depend on the common submodule.
8 #
9 # It will check whether any modifications to the common 'submodule file' has a
10 # a valid commit SHA1 that exists in the common module.
11
12 def commit_exists(sha1, gitdir):
13     """Returns True if the sha1 is a valid commit in the given
14     git directory"""
15     # FIXME: We're using git-show for the time being, but there's a small
16     # risk that there might be a valid SHA1 for a non-commit object.
17     env = os.environ.copy()
18     env["GIT_DIR"] = gitdir
19     sub = subprocess.Popen(["git", "show", sha1], env=env,
20                            stdout=subprocess.PIPE,
21                            stderr=subprocess.PIPE)
22     while True:
23         res = sub.poll()
24         if res != None:
25             return res == 0
26
27 # location of the common git module
28 COMMON_GIT_DIR = "/git/gstreamer/common.git"
29
30 pushvalid = True
31
32 print "=> Checking for integrity of common submodule changes"
33 print
34
35 for line in sys.stdin.readlines():
36     # ref is the ref to be modified
37     # old is the old commit it was pointing to
38     # new is the new commit it was pointing to
39     old, new, ref = line.split(' ', 2)
40
41     # 1. Get the latest change to common (if there was any changes)
42     sub = subprocess.Popen(["git-diff", "%s..%s" % (old, new, ), "--", "common"],
43                            stdout=subprocess.PIPE)
44     stdout, stderr = sub.communicate()
45     if stdout != "":
46         # Format of submodule special files
47         # Subproject commit <SHA1>
48
49         # we get a diff, therefore only grab the last line
50         lastline = stdout.strip().rsplit('\n',1)[-1]
51         if not lastline.startswith("+Subproject commit"):
52             # this is bad, it means the diff has changed to something completely
53             # different
54             continue
55         subsha1 = lastline.rsplit(' ', 1)[-1]
56         print "   Pack wants common to point to", subsha1
57         if not commit_exists(subsha1, COMMON_GIT_DIR):
58             print "   /!\\ Commit does not exist in common git module /!\\"
59             print "   /!\\ for ref", ref
60             pushvalid = False
61             break
62
63         # 2. Figure out if that commit exists in the common submodule
64         # (use GIT_DIR to execute commands in that directory)
65
66 if pushvalid:
67     print "   Incoming packet valid, proceeding to actual commit"
68     sys.exit(0)
69 else:
70     print "   Attempting to push commits containing modifications to common"
71     print "   that have not been commited to the actuall common module."
72     print
73     print "   First push your changes to common/ before pushing the changes"
74     print "   to the module using it."
75     sys.exit(-1)
76