2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
6 # This script is intended to be run as a git update hook. It ensures that all
7 # commits adhere to the copyright header convention for the Arvados project,
8 # which is documented at
10 # https://dev.arvados.org/projects/arvados/wiki/Coding_Standards#Copyright-headers
18 echo "Enforcing copyright headers..."
20 # Load the .licenseignore file
21 LICENSEIGNORE=`mktemp`
22 git show ${NEWREV}:.licenseignore > "${LICENSEIGNORE}" 2>/dev/null
23 if [[ "$?" != "0" ]]; then
24 # e.g., .licenseignore does not exist
27 IFS=$'\n' read -a ignores -r -d $'\000' < "$LICENSEIGNORE" || true
33 for rev in $(git rev-list --objects $OLDREV..$NEWREV --not --branches='*' | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)'| sed -n 's/^blob //p'); do
35 IFS="$oldIFS" read -r -a array <<<"$rev"
39 # Make sure to skip files that match patterns in .licenseignore
41 for pattern in "${ignores[@]}"; do
42 if [[ ${fnm} == ${pattern} ]]; then
46 if [[ ${ignore} = 1 ]]; then continue; fi
48 HEADER=`git show ${sha} | head -n20 | egrep -A3 -B1 'Copyright.*All rights reserved.'`
50 if [[ ! "$HEADER" =~ "SPDX-License-Identifier:" ]]; then
51 if [[ "$EXITCODE" == "0" ]]; then
56 echo "missing or invalid copyright header in file ${fnm}"
62 if [[ "$EXITCODE" != "0" ]]; then
64 echo "[POLICY] all files must contain copyright headers, for more information see"
66 echo " https://dev.arvados.org/projects/arvados/wiki/Coding_Standards#Copyright-headers"