Script to check the diff content of files in output of git status for foul words, variants of those words and repeated chars.
Will not work on Windhose.
Personally, I don't like to mess around with git history, so I try to keep the project history as readable and clean as I can.
Now, I'm also someone who likes to use the same non-sensical words to test stuff or during quick implementations:
make it work, make it right, make it fast.
The problem is I don't always catch everything before committing stuff when I make it right.
This is me accepting I have bad habits, and working around them.
So what if I write let dink = '';
?
The hook will catch this and make me aware of it, giving me the option to either stop the commit or to go ahead and push it into the repository's history.
Now I can at least be aware when commiting sinful (oh so sinful) things into the repo's history.
- Install requirements.txt
pip install -r requirements.txt
- Copy
config.toml.default
toconfig.toml
andassets/violations.toml.default
toassets/violations.toml
. - Create pre-commit hook somewhere you can easily access
mkdir -p ~/.git-templates/hooks
vim ~/.git-templates/hooks/pre-commit
- Call the script from inside the hook
#!/bin/sh
# Add other pre-commit hooks
python /PATH/TO/slapper.py
- Make hook executable
chmod u+x ~/.git-templates/hooks/pre-commit
- Set global rule in git to call this on commit in every repository Reminder: You could also set this per repository
git config --global core.hooksPath ~/.git-templates/hooks/
The rules for all will be used as baseline.
Different (basic regex) patterns/words can be added to specific file extension identifiers, to overwrite the eventual result.
foul
sections will be appended, while acceptable
sections will omit existing checks.
[all]
[all.foul]
words = [
"dink",
"poop",
]
[css]
[css.foul]
words = ["test"]
[css.acceptable]
words = ["poop"]
The resulting foul_words will be dink, test
.
The same applies to patterns.
Tests are located in slapper/tests
and require the py.test module.
Optional: Create a virtual environment to test.
python -m virtualenv .venv
source .venv/bin/activate
Install pytest
pip install pytest
Navigate to the slapper
directory and run the tests.
python -m pytest -v
Smile as you watch the tests pass.