Change the pattern matching for our copyright header so that it doesn't croak
[arvados-dev.git] / git / hooks / coding-standards.sh
index bc75a582ebc82c17e71b7c014717e85929210a4d..d74c705eb569cb89450071c86cc35ef72154e716 100755 (executable)
@@ -1,5 +1,9 @@
 #!/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
@@ -13,6 +17,34 @@ $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'
 
@@ -24,7 +56,7 @@ $broken_commit_message = /Please enter a commit message to explain why this merg
 $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 #|no issue #)/i
+$refs_or_closes_or_no_issue = /(refs #|closes #|fixes #|no issue #)/i
 
 # enforced custom commit message format
 def check_message_format