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 if ENV.has_key?('GL_OPTION_SKIP_DCO_CHECK')
21 puts "Skipping DCO check..."
25 puts "Enforcing DCO signoff..."
26 puts "(#{$refname}) (#{$oldrev[0,6]}) (#{$newrev[0,6]})"
28 $regex = /\[ref: (\d+)\]/
30 $arvados_DCO = /Arvados-DCO-1.1-Signed-off-by:/
32 # enforced DCO signoff in commit message
33 def check_message_format
34 if ($newrev[0,6] == '000000')
35 # A branch is being deleted. Do not check old commits for DCO signoff!
37 elsif ($oldrev[0,6] == '000000')
38 if $refname != 'refs/heads/main'
39 # A new branch was pushed. Check all new commits in this branch.
40 all_revs = `git log --pretty=format:%H main..#{$newrev}`.split("\n")
42 # When does this happen?
46 all_revs = `git rev-list --first-parent #{$oldrev}..#{$newrev}`.split("\n")
51 all_revs.each do |rev|
52 message = `git cat-file commit #{rev} | sed '1,/^$/d' | grep -E "Arvados-DCO-1.1-Signed-off-by: .+@.+\..+"`
54 if ! $arvados_DCO.match(message)
55 puts "\n[POLICY] Rejected commit: missing Arvados-DCO-1.1-Signed-off-by line"
56 puts "\n******************************************************************\n"
57 puts "\nOffending commit: #{rev}\n"
58 puts "\nOffending commit message:\n\n"
59 puts `git cat-file commit #{rev} | sed '1,/^$/d'`
60 puts "\n******************************************************************\n"
62 puts "\nFor more information, see\n"
63 puts "\n https://dev.arvados.org/projects/arvados/wiki/Developer_Certificate_Of_Origin\n"
70 puts "Enforcing DCO signoff: FAIL"
73 puts "Enforcing DCO signoff: PASS"