3 # This script can be installed as a git update hook.
5 # It can also be installed as a gitolite 'hooklet' in the
6 # hooks/common/update.secondary.d/ directory.
8 # NOTE: this script runs under the same assumptions as the 'update' hook, so
9 # the starting directory must be maintained and arguments must be passed on.
16 puts "Enforcing DCO signoff: (#{$refname}) (#{$oldrev[0,6]}) (#{$newrev[0,6]})"
18 $regex = /\[ref: (\d+)\]/
20 $arvados_DCO = /Arvados-DCO-1.1-Signed-off-by:/
22 # enforced DCO signoff in commit message
23 def check_message_format
24 if ($newrev[0,6] == '000000')
25 # A branch is being deleted. Do not check old commits for DCO signoff!
27 elsif ($oldrev[0,6] == '000000')
28 if $refname != 'refs/heads/master'
29 # A new branch was pushed. Check all new commits in this branch.
30 all_revs = `git log --pretty=format:%H master..#{$newrev}`.split("\n")
32 # When does this happen?
36 all_revs = `git rev-list --first-parent #{$oldrev}..#{$newrev}`.split("\n")
41 all_revs.each do |rev|
42 message = `git cat-file commit #{rev} | sed '1,/^$/d' | grep -E "Arvados-DCO-1.1-Signed-off-by: .+@.+\..+"`
44 if ! $arvados_DCO.match(message)
45 puts "\n[POLICY] Rejected commit: missing Arvados-DCO-1.1-Signed-off-by line"
46 puts "\n******************************************************************\n"
47 puts "\nOffending commit: #{rev}\n"
48 puts "\nOffending commit message:\n\n"
49 puts `git cat-file commit #{rev} | sed '1,/^$/d'`
50 puts "\n******************************************************************\n"
52 puts "\nFor more information, see\n"
53 puts "\n https://dev.arvados.org/projects/arvados/wiki/Developer_Certificate_Of_Origin\n"