mirror of
https://github.com/infeeeee/dyn2py
synced 2025-12-16 22:16:18 +01:00
Add example git hook
This commit is contained in:
27
pre-commit
Normal file
27
pre-commit
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Create a list of files from staged files:
|
||||
mapfile -t NEW_FILES <<<$(git diff --name-only --cached)
|
||||
|
||||
# Go through staged files:
|
||||
for f in "${NEW_FILES[@]}"; do
|
||||
|
||||
# Export python files, only from Dynamo files.
|
||||
# On Windows line ending is always CRLF, so remove CR with tr.
|
||||
mapfile -t PY_FILES <<<$(dyn2py --force --filter dyn --loglevel HEADLESS "$f" | tr -d "\r")
|
||||
|
||||
# Check if something was exported:
|
||||
if [[ "${PY_FILES[@]}" ]]; then
|
||||
|
||||
# Go through exported files:
|
||||
for p in "${PY_FILES[@]}"; do
|
||||
|
||||
# Check if file exists:
|
||||
if [ -f "$p" ]; then
|
||||
|
||||
# Stage file:
|
||||
git add "$p"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user