Skip to content

Commit

Permalink
chore: add githooks
Browse files Browse the repository at this point in the history
  • Loading branch information
agnkuz committed Jan 15, 2024
1 parent abcf36e commit 57e1ea6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

#ignore merges
isMerge=$(git rev-parse -q --verify MERGE_HEAD)
if [ -n "$isMerge" ]; then
exit
fi

# fix with linter
dart fix --apply

# Regexp for grep to only choose some file extensions for formatting
exts="\.\(dart\)$"
echo "Pre-commit: formatting changed files"
# Format staged files
for file in $(git diff --cached --name-only --diff-filter=ACMR | grep $exts); do
echo "Formatting $file"
dart format --line-length=120 $file
git add $file
done
17 changes: 17 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

printf "\e[33;1m%s\e[0m\n" 'Running the Flutter analyzer'
flutter analyze
if [ $? -ne 0 ]; then
printf "\e[31;1m%s\e[0m\n" 'Flutter analyzer error'
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running the Flutter analyzer'

printf "\e[33;1m%s\e[0m\n" 'Running unit tests'
flutter test
if [ $? -ne 0 ]; then
printf "\e[31;1m%s\e[0m\n" 'Unit tests error'
exit 1
fi
printf "\e[33;1m%s\e[0m\n" 'Finished running unit tests'

0 comments on commit 57e1ea6

Please sign in to comment.