Skip to content

Commit c57f37e

Browse files
committed
Check syntax for changed shell scripts
If any relevant script is found, the hook runs 'bash -n' to verify its syntax. Change-Id: If1f29966228d36bdb4022a822a14e87956bbb825
1 parent 06a3780 commit c57f37e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

scripts/pre-commit.hook

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,21 @@ for FILE in $C_FILES; do
207207
fi
208208
done
209209

210+
# Check syntax for changed shell scripts
211+
SHELL_FILES=()
212+
for file in "${FILES[@]}"; do
213+
if [[ "$file" =~ ^scripts/common\.sh$ || "$file" =~ ^scripts/.*\.hook$ ]]; then
214+
SHELL_FILES+=("$file")
215+
fi
216+
done
217+
if [ "${#SHELL_FILES[@]}" -gt 0 ]; then
218+
for file in "${SHELL_FILES[@]}"; do
219+
if ! bash -n "$file"; then
220+
throw "Syntax errors detected in $file." >&2
221+
fi
222+
done
223+
fi
224+
210225
# Show insertion and deletion counts.
211226
if [ "${#FILES[@]}" -gt 0 ]; then
212227
echo "Following files were changed:"

0 commit comments

Comments
 (0)