Skip to content

Instantly share code, notes, and snippets.

@DanielCardonaRojas
Last active November 8, 2021 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielCardonaRojas/d8d8d34304856c850ce5179fc90559ff to your computer and use it in GitHub Desktop.
Save DanielCardonaRojas/d8d8d34304856c850ce5179fc90559ff to your computer and use it in GitHub Desktop.
githooks for flutter development
#!/bin/sh
if ! head -1 "$1" | grep -qE "^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+?\))?: .{1,}$"; then
echo "Aborting commit. Your commit message is invalid." >&2
exit 1
fi
if ! head -1 "$1" | grep -qE "^.{1,88}$"; then
echo "Aborting commit. Your commit message is too long." >&2
exit 1
fi
# echo "$(cat $1)" | commitlint
#!/bin/bash
trap 'exit 130' INT
staged_files=$(git --no-pager diff --cached --name-only --diff-filter=M)
git_grep=$(git --no-pager grep -l -E --cached "path:\s+\.\.\/\.\.\/" $staged_files)
if match=$git_grep && echo $git_grep | grep -q "pubspec"; then
echo "Please remove local dependencies in $match"
exit 1
fi
set -e
directories=$(git --no-pager diff --cached --dirstat=cumulative,0 | awk '{print $2}' | cut -d "/" -f1 | uniq)
for dir in $directories; do
if [ -f "$dir/analysis_options.yaml" ]; then
(cd $dir && flutter analyze)
fi
done
#!/bin/bash
set -e
trap 'exit 130' INT
directories=$(git --no-pager diff HEAD~1 --cached --dirstat=cumulative | awk '{print $2}' | cut -d "/" -f1 | uniq)
for dir in $directories; do
if [ -d "./$dir/test" ]; then
echo "Testing $dir..."
(cd $dir && flutter test)
fi
done
@DanielCardonaRojas
Copy link
Author

DanielCardonaRojas commented Oct 1, 2021

For mono repos with multiple packages inside

rename these by removing .sh extension and put in .githooks folder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment