Last active
March 9, 2024 07:44
-
-
Save shahin-you/2760f91c5d6c839dd4d4d9e942902e33 to your computer and use it in GitHub Desktop.
pre-commit hook to find `TODO` comments + simple check for code folder vs test folder changes.
This file contains 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/sh | |
# Check for "TODO" in staged files | |
TODO_FOUND=$(git diff --cached --name-only --diff-filter=AM | grep -E '\.(cpp|c|cc|h|hpp)$' | xargs -r grep -l 'TODO') | |
if [ ! -z "$TODO_FOUND" ]; then | |
echo "Warning: TODO found in the following files:" | |
echo "$TODO_FOUND" | |
echo "Consider addressing the TODOs or creating tickets for them before committing." | |
# Uncomment the next line to block the commit until TODOs are addressed | |
# exit 1 | |
fi | |
# Get list of changed C++ source files | |
CPP_CHANGES=$(git diff --cached --name-only --diff-filter=AM | grep -E '\.cpp$') | |
# Placeholder for test directory path | |
TEST_DIR="tests/" | |
# Check for changes in test files | |
TEST_CHANGES=$(git diff --cached --name-only --diff-filter=AM | grep -E "^$TEST_DIR") | |
if [ ! -z "$CPP_CHANGES" ] && [ -z "$TEST_CHANGES" ]; then | |
echo "Warning: C++ source files have changed, but no changes detected in unit tests." | |
echo "Ensure new functionalities have corresponding unit tests." | |
# Uncomment the next line to block the commit | |
# exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment