File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+ #
3+ # Copyright 2025 SmartThings, Inc.
4+ # Licensed under the Apache License, Version 2.0
5+ #
6+ # pre-commit
7+ #
8+ # - Soft link into .git/hooks/pre-commit
9+ # - $ ln -s ../../tools/pre-commit .git/hooks/pre-commit
10+ # - Ensure executable
11+
12+ set -e
13+
14+ # Get changed files that are Added or Modified
15+ if [[ " $1 " ]]; then
16+ files=$( find $1 -type f -follow -print)
17+ else
18+ files=$( git diff --staged --name-only --diff-filter=AM)
19+ fi
20+
21+ fail=0
22+ for file in $files ; do
23+ # Only process .lua files
24+ case " $file " in
25+ * .lua)
26+ # Skip if not a regular file
27+ [ -f " $file " ] || continue
28+
29+ # Check if file is not empty, is a SmartThings driver and has the copyright header
30+ if [ -s " $file " ] && [[ " $file " =~ " drivers/SmartThings" ]] \
31+ && [[ ! $( grep $file -P -e " -{2,} Copyright \d{4}(?:-\d{4})? SmartThings" ) ]]; then
32+ echo " $file : SmartThings Copyright missing from file"
33+ fail=1
34+ fi
35+
36+ # Check if file is non-empty and does NOT end with a newline
37+ if [ -s " $file " ] && [ -n " $( tail -c 1 " $file " ) " ]; then
38+ echo " $file : Missing newline at end of file"
39+ fail=1
40+ fi
41+ ;;
42+ esac
43+ done
44+
45+ exit $fail
You can’t perform that action at this time.
0 commit comments