diff --git a/justfile b/justfile index a9138f8..9db6c0b 100644 --- a/justfile +++ b/justfile @@ -131,6 +131,10 @@ install-hooks: # install pre-push hook echo "just test" > .git/hooks/pre-push&&chmod +x .git/hooks/pre-push +black-hook: + # ensures that all your commits contain Python code formatted according to Black’s rules. + cp pre-commit-black .git/hooks/pre-commit&&chmod +x .git/hooks/pre-commit + # bootstrap your virtualenv (deprecated) setenv VIRTUALENV: @echo Create virtualenv and use it to install requirements diff --git a/pre-commit-black b/pre-commit-black new file mode 100644 index 0000000..267aeb9 --- /dev/null +++ b/pre-commit-black @@ -0,0 +1,10 @@ +#!/bin/sh + +# Run Black on all Python files +files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$') +if [ -n "$files" ]; then + echo "Running Black on Python files..." + black $files + # Add the formatted files back to the staging area + git add $files +fi \ No newline at end of file