Compare commits
2 Commits
e6ed36ffbe
...
9123c23633
Author | SHA1 | Date |
---|---|---|
Alex Selimov | 9123c23633 | 4 months ago |
Alex Selimov | 9530e2107d | 4 months ago |
@ -0,0 +1,20 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# This is a script which can be included in a pre-commit hook to auto format code using specified
|
||||||
|
# tools. In this script we utilize black for python and intelliJ for Java.
|
||||||
|
|
||||||
|
# Only run if black is installed
|
||||||
|
if hash black 2>/dev/null; then
|
||||||
|
|
||||||
|
# Find all of the .py files in the current git repo, apply black formatting to them and then
|
||||||
|
# add them again
|
||||||
|
git diff --cached --name-status | \
|
||||||
|
grep -v '^D' | grep '\.py' | \
|
||||||
|
sed 's/[A-Z][ \t]*//' | \
|
||||||
|
xargs black 2>&1| \
|
||||||
|
grep '^reformatted' | \
|
||||||
|
sed 's/reformatted[ \t]//' | \
|
||||||
|
xargs git add
|
||||||
|
|
||||||
|
else
|
||||||
|
"Black isn't installed so not formatting python code"
|
||||||
|
fi
|
Loading…
Reference in new issue