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