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"
31 error_badcommon = False
32 error_badcommit = False
34 print "=> Checking for integrity of common submodule changes"
37 for line in sys.stdin.readlines():
38 # ref is the ref to be modified
39 # old is the old commit it was pointing to
40 # new is the new commit it was pointing to
41 old, new, ref = line.split(' ', 2)
43 # 1. Get the latest change to common (if there was any changes)
44 sub = subprocess.Popen(["git", "diff", "%s..%s" % (old, new, ), "--", "common"],
45 stdout=subprocess.PIPE)
46 stdout, stderr = sub.communicate()
48 # Format of submodule special files
49 # Subproject commit <SHA1>
51 # we get a diff, therefore only grab the last line
52 lastline = stdout.strip().rsplit('\n',1)[-1]
53 if not lastline.startswith("+Subproject commit"):
54 # this is bad, it means the diff has changed to something completely
57 subsha1 = lastline.rsplit(' ', 1)[-1]
58 print " Pack wants common to point to", subsha1
59 if not commit_exists(subsha1, COMMON_GIT_DIR):
60 print " /!\\ Commit does not exist in common git module /!\\"
61 print " /!\\ for ref", ref
65 # 2. Figure out if that commit exists in the common submodule
66 # (use GIT_DIR to execute commands in that directory)
68 # Get the commit message
69 sub = subprocess.Popen(["git", "log", "--format=%s",
70 "%s..%s" % (old, new, )], stdout=subprocess.PIPE)
71 stdout, stderr = sub.communicate()
73 for line in stdout.strip().rsplit('\n',1):
74 if line.startswith("!"):
75 error_badcommit = True
80 print " Incoming packet valid, proceeding to actual commit"
84 print " Attempting to push commits with commit messages that start"
85 print " with '!'. Commit messages starting with '!' are reserved"
86 print " for private branches to prevent the commits from accidentally"
87 print " getting to the main repository."
89 print " Attempting to push commits containing modifications to common"
90 print " that have not been commited to the actuall common module."
92 print " First push your changes to common/ before pushing the changes"
93 print " to the module using it."