Skip to content

Commit

Permalink
Only run python.pre_commit after modifying and staging .py files
Browse files Browse the repository at this point in the history
  • Loading branch information
shailshouryya committed Apr 6, 2023
1 parent 45c4721 commit 1dad58a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pre-commit-nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ EOF
exit 1
fi

alias python=python3
python -m python.pre_commit
py_files_changed=$(git diff --staged --name-only -- "*.py")
if [ "$py_files_changed" = "" ]
then
printf "No python files changed! \n\n"
else
alias python=python3
printf "Python files changed, running python.pre_commit to verify changes...\n\n"
python3 -m python.pre_commit
fi

# If there are whitespace errors, print the offending file names and fail.
exec git diff-index --check --cached $against --

0 comments on commit 1dad58a

Please sign in to comment.