[ARVADOS-DEV] updated: a4fabe9c50a723d92be7e32c0b88738e32fcb58e
Git user
git at public.arvados.org
Thu Jun 17 14:00:37 UTC 2021
Summary of changes:
git/hooks/{check-copyright-headers.rb => old-check-copyright-headers.rb} | 0
git/hooks/{coding-standards.rb => old-coding-standards.rb} | 0
git/hooks/{enforce-dco-signoff.rb => old-enforce-dco-signoff.rb} | 0
3 files changed, 0 insertions(+), 0 deletions(-)
copy git/hooks/{check-copyright-headers.rb => old-check-copyright-headers.rb} (100%)
copy git/hooks/{coding-standards.rb => old-coding-standards.rb} (100%)
copy git/hooks/{enforce-dco-signoff.rb => old-enforce-dco-signoff.rb} (100%)
via a4fabe9c50a723d92be7e32c0b88738e32fcb58e (commit)
from 5638ea2df2232c1c5fdd45877014f80c88eb331e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit a4fabe9c50a723d92be7e32c0b88738e32fcb58e
Author: Ward Vandewege <ward at curii.com>
Date: Thu Jun 17 09:44:25 2021 -0400
In preparation of the migration to 'main', make a copy of the commit
hooks that reference the old 'master' branch, so that we can migrate
gradually.
refs #17817
Arvados-DCO-1.1-Signed-off-by: Ward Vandewege <ward at curii.com>
diff --git a/git/hooks/old-check-copyright-headers.rb b/git/hooks/old-check-copyright-headers.rb
new file mode 100755
index 0000000..b4b8d94
--- /dev/null
+++ b/git/hooks/old-check-copyright-headers.rb
@@ -0,0 +1,153 @@
+#!/usr/bin/env ruby
+
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+# This script can be installed as a git update hook.
+
+# It can also be installed as a gitolite 'hooklet' in the
+# hooks/common/update.secondary.d/ directory.
+
+# NOTE: this script runs under the same assumptions as the 'update' hook, so
+# the starting directory must be maintained and arguments must be passed on.
+
+$refname = ARGV[0]
+$oldrev = ARGV[1]
+$newrev = ARGV[2]
+$user = ENV['USER']
+
+puts "Enforcing copyright headers..."
+puts "(#{$refname}) (#{$oldrev[0,6]}) (#{$newrev[0,6]})"
+
+def load_licenseignore
+ $licenseignore = `git show #{$newrev}:.licenseignore 2>/dev/null`.gsub(/\./,'\\.').gsub(/\*/,'.*').gsub(/\?/,'.').split("\n")
+end
+
+def check_file(filename, header, broken)
+ ignore = false
+ $licenseignore.each do |li|
+ if filename =~ /#{li}/
+ ignore = true
+ end
+ end
+ return broken if ignore
+
+ if header !~ /SPDX-License-Identifier:/
+ if not broken
+ puts "\nERROR\n"
+ end
+ puts "missing or invalid copyright header in file #{filename}"
+ broken = true
+ end
+ return broken
+end
+
+# enforce copyright headers
+def check_copyright_headers
+ if ($newrev[0,6] == '000000')
+ # A branch is being deleted. Do not check old commits for DCO signoff!
+ all_objects = []
+ commits = []
+ elsif ($oldrev[0,6] == '000000')
+ if $refname != 'refs/heads/master'
+ # A new branch was pushed. Check all new commits in this branch.
+ puts "git rev-list --objects master..#{$newrev} | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)'| sed -n 's/^blob //p'"
+ blob_objects = `git rev-list --objects master..#{$newrev} | git cat-file --follow-symlinks --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)'| sed -n 's/^blob //p'`.split("\n")
+ commit_objects = `git rev-list --objects master..#{$newrev} | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)'| sed -n 's/^commit //p'`.split("\n")
+ all_objects = blob_objects + commit_objects
+ commits = `git rev-list master..#{$newrev}`.split("\n")
+ else
+ # When does this happen?
+ puts "UNEXPECTED ERROR"
+ exit 1
+ end
+ else
+ blob_objects = `git rev-list --objects #{$oldrev}..#{$newrev} --not --branches='*' | git cat-file --follow-symlinks --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)'| sed -n 's/^blob //p'`.split("\n")
+ commit_objects = `git rev-list --objects #{$oldrev}..#{$newrev} | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)'| sed -n 's/^commit //p'`.split("\n")
+ all_objects = blob_objects + commit_objects
+ commits = `git rev-list #{$oldrev}..#{$newrev}`.split("\n")
+ end
+
+ broken = false
+
+ all_objects.each do |rev|
+ ignore = false
+ tmp = rev.split(' ')
+ if tmp[2].nil?
+ # git object of type 'commit'
+ # This could be a new file that was added in this commit
+ # If this wasn't a bare repo, we could run the following to get the list of new files in this commit:
+ # new_files = `git show #{tmp[0]} --name-only --diff-filter=A --pretty=""`.split("\n")
+ # Instead, we just look at all the files touched in the commit and check the diff to see
+ # see if it is a new file. This could prove brittle...
+ files = `git show #{tmp[0]} --name-only --pretty=""`.split("\n")
+ files.each do |f|
+ filename = f
+ commit = `git show #{tmp[0]} -- #{f}`
+ # Only consider files, not symlinks (mode 120000)
+ if commit =~ /^new file mode (100644|10755)\nindex 000000/
+ headerCount = 0
+ lineCount = 0
+ header = ""
+ previousLine = ""
+ commit.each_line do |line|
+ if ((headerCount == 0) and (line =~ /Copyright.*All rights reserved./))
+ header = previousLine
+ header += line
+ headerCount = 1
+ elsif ((headerCount > 0) and (headerCount < 3))
+ header += line
+ headerCount += 1
+ elsif (headerCount == 3)
+ break
+ end
+ previousLine = line
+ lineCount += 1
+ if lineCount > 50
+ break
+ end
+ end
+ broken = check_file(filename, header, broken)
+ end
+ end
+ else
+ # git object of type 'blob'
+ filename = tmp[2]
+ # test if this is a symlink.
+ # Get the tree for each revision we are considering, find the blob hash in there, check the mode at start of line.
+ # Stop looking at revisions once we have a match.
+ symlink = false
+ commits.each do |r|
+ tree = `git cat-file -p #{r}^{tree}`
+ if tree =~ /#{tmp[0]}/
+ if tree =~ /^120000.blob.#{tmp[0]}/
+ symlink = true
+ end
+ break
+ end
+ end
+ if symlink == false
+ header = `git show #{tmp[0]} | head -n20 | egrep -A3 -B1 'Copyright.*All rights reserved.'`
+ broken = check_file(filename, header, broken)
+ else
+ #puts "#{filename} is a symbolic link, skipping"
+ end
+ end
+ end
+
+ if broken
+ puts
+ puts "[POLICY] all files must contain copyright headers, for more information see"
+ puts
+ puts " https://dev.arvados.org/projects/arvados/wiki/Coding_Standards#Copyright-headers"
+ puts
+ puts "Enforcing copyright headers: FAIL"
+ exit 1
+
+ end
+ puts "Enforcing copyright headers: PASS"
+end
+
+load_licenseignore
+check_copyright_headers
diff --git a/git/hooks/old-coding-standards.rb b/git/hooks/old-coding-standards.rb
new file mode 100755
index 0000000..4097d1a
--- /dev/null
+++ b/git/hooks/old-coding-standards.rb
@@ -0,0 +1,149 @@
+#!/usr/bin/env ruby
+
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+# This script can be installed as a git update hook.
+
+# It can also be installed as a gitolite 'hooklet' in the
+# hooks/common/update.secondary.d/ directory.
+
+# NOTE: this script runs under the same assumptions as the 'update' hook, so
+# the starting directory must be maintained and arguments must be passed on.
+
+$refname = ARGV[0]
+$oldrev = ARGV[1]
+$newrev = ARGV[2]
+$user = ENV['USER']
+
+def blacklist bl
+ if ($newrev[0,6] == '000000')
+ # A branch is being deleted. Do not check old commits for DCO signoff!
+ all_revs = []
+ elsif ($oldrev[0,6] == '000000')
+ if $refname != 'refs/heads/master'
+ # A new branch was pushed. Check all new commits in this branch.
+ all_revs = `git log --pretty=format:%H master..#{$newrev}`.split("\n")
+ else
+ # When does this happen?
+ all_revs = [$newrev]
+ end
+ else
+ all_revs = `git rev-list #{$oldrev}..#{$newrev}`.split("\n")
+ end
+
+ all_revs.each do |rev|
+ bl.each do |b|
+ if rev == b
+ puts "Revision #{b} is blacklisted, you must remove it from your branch (possibly using git rebase) before you can push."
+ exit 1
+ end
+ end
+ end
+end
+
+blacklist ['26d74dc0524c87c5dcc0c76040ce413a4848b57a']
+
+# Only enforce policy on the master branch
+exit 0 if $refname != 'refs/heads/master'
+
+puts "Enforcing Policies..."
+puts "(#{$refname}) (#{$oldrev[0,6]}) (#{$newrev[0,6]})"
+
+$regex = /\[ref: (\d+)\]/
+
+$broken_commit_message = /Please enter a commit message to explain why this merge is necessary/
+$wrong_way_merge_master = /Merge( remote-tracking)? branch '([^\/]+\/)?master' into/
+$merge_master = /Merge branch '[^']+'((?! into)| into master)/
+$pull_merge = /Merge branch 'master' of /
+$refs_or_closes_or_no_issue = /(refs #|closes #|fixes #|no issue #)/i
+
+# enforced custom commit message format
+def check_message_format
+ all_revs = `git rev-list --first-parent #{$oldrev}..#{$newrev}`.split("\n")
+ merge_revs = `git rev-list --first-parent --min-parents=2 #{$oldrev}..#{$newrev}`.split("\n")
+ # single_revs = `git rev-list --first-parent --max-parents=1 #{$oldrev}..#{$newrev}`.split("\n")
+ broken = false
+ no_ff = false
+
+ merge_revs.each do |rev|
+ message = `git cat-file commit #{rev} | sed '1,/^$/d'`
+ if $wrong_way_merge_master.match(message)
+ puts "\n[POLICY] Only non-fast-forward merges into master are allowed. Please"
+ puts "reset your master branch:"
+ puts " git reset --hard origin/master"
+ puts "and then merge your branch with the --no-ff option:"
+ puts " git merge your-branch --no-ff\n"
+ puts "Remember to add a reference to an issue number in the merge commit!\n"
+ puts "\n******************************************************************\n"
+ puts "\nOffending commit: #{rev}\n"
+ puts "\nOffending commit message:\n"
+ puts message
+ puts "\n******************************************************************\n"
+ puts "\n\n"
+ broken = true
+ no_ff = true
+ elsif $pull_merge.match(message)
+ puts "\n[POLICY] This appears to be a git pull merge of remote master into local"
+ puts "master. In order to maintain a linear first-parent history of master,"
+ puts "please reset your branch and remerge or rebase using the latest master.\n"
+ puts "\n******************************************************************\n"
+ puts "\nOffending commit: #{rev}\n"
+ puts "\nOffending commit message:\n\n"
+ puts message
+ puts "\n******************************************************************\n"
+ puts "\n\n"
+ broken = true
+ elsif not $merge_master.match(message) and not
+ puts "\n[POLICY] This does not appear to be a merge of a feature"
+ puts "branch into master. Merges must follow the format"
+ puts "\"Merge branch 'feature-branch'\".\n"
+ puts "\n******************************************************************\n"
+ puts "\nOffending commit: #{rev}\n"
+ puts "\nOffending commit message:\n\n"
+ puts message
+ puts "\n******************************************************************\n"
+ puts "\n\n"
+ broken = true
+ end
+ end
+
+ all_revs.each do |rev|
+ message = `git cat-file commit #{rev} | sed '1,/^$/d'`
+ if $broken_commit_message.match(message)
+ puts "\n[POLICY] Rejected broken commit message for including boilerplate"
+ puts "instruction text.\n"
+ puts "\n******************************************************************\n"
+ puts "\nOffending commit: #{rev}\n"
+ puts "\nOffending commit message:\n\n"
+ puts message
+ puts "\n******************************************************************\n"
+ puts "\n\n"
+ broken = true
+ end
+
+ # Do not test when the commit is a no_ff merge (which will be rejected), because
+ # this test will complain about *every* commit in the merge otherwise, obscuring
+ # the real reason for the rejection (the no_ff merge)
+ if not no_ff and not $refs_or_closes_or_no_issue.match(message)
+ puts "\n[POLICY] All commits to master must include an issue using \"refs #\" or"
+ puts "\"closes #\", or specify \"no issue #\"\n"
+ puts "\n******************************************************************\n"
+ puts "\nOffending commit: #{rev}\n"
+ puts "\nOffending commit message:\n\n"
+ puts message
+ puts "\n******************************************************************\n"
+ puts "\n\n"
+ broken = true
+ end
+ end
+
+ if broken
+ puts "Enforcing Policies: FAIL"
+ exit 1
+ end
+ puts "Enforcing Policies: PASS"
+end
+
+check_message_format
diff --git a/git/hooks/old-enforce-dco-signoff.rb b/git/hooks/old-enforce-dco-signoff.rb
new file mode 100755
index 0000000..191a34b
--- /dev/null
+++ b/git/hooks/old-enforce-dco-signoff.rb
@@ -0,0 +1,71 @@
+#!/usr/bin/env ruby
+
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+# This script can be installed as a git update hook.
+
+# It can also be installed as a gitolite 'hooklet' in the
+# hooks/common/update.secondary.d/ directory.
+
+# NOTE: this script runs under the same assumptions as the 'update' hook, so
+# the starting directory must be maintained and arguments must be passed on.
+
+$refname = ARGV[0]
+$oldrev = ARGV[1]
+$newrev = ARGV[2]
+$user = ENV['USER']
+
+puts "Enforcing DCO signoff..."
+puts "(#{$refname}) (#{$oldrev[0,6]}) (#{$newrev[0,6]})"
+
+$regex = /\[ref: (\d+)\]/
+
+$arvados_DCO = /Arvados-DCO-1.1-Signed-off-by:/
+
+# enforced DCO signoff in commit message
+def check_message_format
+ if ($newrev[0,6] == '000000')
+ # A branch is being deleted. Do not check old commits for DCO signoff!
+ all_revs = []
+ elsif ($oldrev[0,6] == '000000')
+ if $refname != 'refs/heads/master'
+ # A new branch was pushed. Check all new commits in this branch.
+ all_revs = `git log --pretty=format:%H master..#{$newrev}`.split("\n")
+ else
+ # When does this happen?
+ all_revs = [$newrev]
+ end
+ else
+ all_revs = `git rev-list --first-parent #{$oldrev}..#{$newrev}`.split("\n")
+ end
+
+ broken = false
+
+ all_revs.each do |rev|
+ message = `git cat-file commit #{rev} | sed '1,/^$/d' | grep -E "Arvados-DCO-1.1-Signed-off-by: .+ at .+\..+"`
+
+ if ! $arvados_DCO.match(message)
+ puts "\n[POLICY] Rejected commit: missing Arvados-DCO-1.1-Signed-off-by line"
+ puts "\n******************************************************************\n"
+ puts "\nOffending commit: #{rev}\n"
+ puts "\nOffending commit message:\n\n"
+ puts `git cat-file commit #{rev} | sed '1,/^$/d'`
+ puts "\n******************************************************************\n"
+ puts "\n\n"
+ puts "\nFor more information, see\n"
+ puts "\n https://dev.arvados.org/projects/arvados/wiki/Developer_Certificate_Of_Origin\n"
+ puts "\n\n"
+ broken = true
+ end
+ end
+
+ if broken
+ puts "Enforcing DCO signoff: FAIL"
+ exit 1
+ end
+ puts "Enforcing DCO signoff: PASS"
+end
+
+check_message_format
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list