Created
October 2, 2023 07:37
-
-
Save MrSunshyne/023a404c4946636570725080bccf170c to your computer and use it in GitHub Desktop.
Use a global pre-commit to prevent committing tracked files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir ~/global-git-hooks | |
code ~/global-git-hooks/pre-commit | |
chmod +x ~/global-git-hooks/pre-commit | |
git config --global core.hooksPath ~/global-git-hooks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "Running pre-commit checks..." | |
# Define the directory to check | |
DIRECTORY_TO_CHECK="/home/sun/Projects/<AND_SO_ON>" | |
# Define a list of files that should not be committed in the "entropy" directory | |
FILES_TO_IGNORE=("file1.text" "file2.txt") | |
# Check if any of the ignored files in the specified directory are about to be committed | |
for file in "${FILES_TO_IGNORE[@]}"; do | |
if git diff --cached --name-only | grep -q "$file"; then | |
echo "WARNING: File '$file' is about to be committed but should be ignored." | |
echo "Please unstage or remove it before committing." | |
exit 1 | |
fi | |
done | |
# If no ignored files are found in the specified directory, continue with the commit | |
echo "Files not found in commit. Continuing..." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment