#!/bin/bash # # A hook script to verify that no filenames with capital letters are committed. # Called by "git commit" with no arguments. The hook should # exit with non-zero status after issuing an appropriate message if # it wants to stop the commit. # # Go through all the changed files (except for deleted and unmerged) # Save exit code of last executed action exit_code=0 # Check if file is one of SAS|DDL|CSV|SH and check for uppercase letters mime_pattern="\.(sas|ddl|csv|sh)" # Check for capital letters only in file names extra_pattern="(^|/)[^/]*([A-Z]+)[^/]*\.[A-Za-z]{3}$" # Grep git diff of files to commit files=$( git diff --cached --find-copies --find-renames --name-only --diff-filter=ACMRTXBU | grep -Ei "$mime_pattern" | grep -E "$extra_pattern" ) echo "$files" if [[ -n "$files" ]]; then echo echo "Found files that contain capital letters." echo "Please rename the following files in lowercase, and commit again:" for file in $files; do echo -e '- \E[0;32m'"$file"'\033[0m' done # Abort commit exit_code=1 fi if [ "$exit_code" == "0" ]; then echo echo -e '\033[1m'"Pre-commit validation Passed"'\033[0m' echo else echo echo -e '\033[1m'"Commit Aborted!"'\033[0m' echo fi exit $exit_code