-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·27 lines (22 loc) · 920 Bytes
/
Copy pathpre-commit
File metadata and controls
executable file
·27 lines (22 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/bin/sh
set -e
# select commmitted python and xml files (not deleted)
pythonFilesToFormat="$(git --no-pager diff --name-status --no-color --cached | awk '$1 ~ /^R[0-9]+$/ && $3 ~ /\.py/ {print $3; next}; $1 != "D" && $2 ~ /\.py/ {print $2}')"
xmlFilesToFormat="$(git --no-pager diff --name-status --no-color --cached | awk '$1 ~ /^R[0-9]+$/ && $3 ~ /\.xml/ {print $3; next}; $1 != "D" && $2 ~ /\.xml/ {print $2}')"
echo "Python files to format:"
echo "$pythonFilesToFormat"
for sourceFilePath in $pythonFilesToFormat
do
poetry run black "$(pwd)/$sourceFilePath"
git add $sourceFilePath
done
echo "XML files to format:"
echo "$xmlFilesToFormat"
for sourceFilePath in $xmlFilesToFormat
do
poetry run xmlformat --indent 4 --eof-newline --overwrite --selfclose --infile "$(pwd)/$sourceFilePath" || echo "$(pwd)/$sourceFilePath" is invalid.
git add $sourceFilePath
done
printf "\n"
# run the linters
make lint