Feature/Add git pre-commit hook for yarn format (#2840)

* Set up git pre-commit hook for yarn format

* Update changelog
This commit is contained in:
Hugo Persson
2024-01-10 20:36:10 +01:00
committed by GitHub
parent a47829082e
commit 170b8acc65
3 changed files with 28 additions and 0 deletions

26
git-hooks/pre-commit Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
# Will check if "yarn format" is run before executing.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
echo "Running yarn format"
# Run the command and loop over its output
FILES_TO_STAGE=""
i=0
while IFS= read -r line; do
# Process each line here
((i++))
if [ $i -le 2 ]; then
continue
fi
if [[ $line == Done* ]]; then
break
fi
FILES_TO_STAGE="$FILES_TO_STAGE $line"
done < <(yarn format )
git add $FILES_TO_STAGE
echo "Files formatted. Committing..."