6 # This server-side pre-receive hook is to be put and activated in all modules
7 # that depend on the common submodule.
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.
12 def commit_exists(sha1, gitdir):
13 """Returns True if the sha1 is a valid commit in the given
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)
27 # location of the common git module
28 COMMON_GIT_DIR = "/git/gstreamer/common.git"
32 print "=> Checking for integrity of common submodule changes"
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)
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()
46 # Format of submodule special files
47 # Subproject commit <SHA1>
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
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
63 # 2. Figure out if that commit exists in the common submodule
64 # (use GIT_DIR to execute commands in that directory)
67 print " Incoming packet valid, proceeding to actual commit"
70 print " Attempting to push commits containing modifications to common"
71 print " that have not been commited to the actuall common module."
73 print " First push your changes to common/ before pushing the changes"
74 print " to the module using it."