-
Notifications
You must be signed in to change notification settings - Fork 443
/
check_license.sh
executable file
·34 lines (32 loc) · 1.04 KB
/
check_license.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash -ue
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# Get list of files that have been modified
patterns=$(dirname $0)/exclude-patterns
if CHECK=$(git diff --name-only HEAD * | grep -v -f $patterns | sort -u); then
echo "Checking files currently modified"
else
CHECK=$(git diff-tree --no-commit-id --name-only \
-r $(git log -2 --pretty=format:"%h") \
| grep -v -f $patterns | sort -u)
echo "Checking files in last commit"
fi
set -o pipefail
echo "Checking committed files for SPDX-License-Identifier headers ..."
if [ -z "$CHECK" ]; then
echo "All files have SPDX-License-Identifier headers"
exit 0
fi
if missing=$(echo $CHECK | xargs grep -L "SPDX-License-Identifier"); then
echo "All files have SPDX-License-Identifier headers"
exit 0
fi
echo "The following files are missing SPDX-License-Identifier headers:"
echo "$missing"
echo
echo "Please replace the Apache license header comment text with:"
echo "SPDX-License-Identifier: Apache-2.0"
exit 1