chmod +x .git/hooks/pre-commit
#!/bin/sh
# pre-commit hook to run flutter analyze
# Stash any changes to the working directory
stash_name="pre-commit-$(date +%s)"
git stash save -q --keep-index $stash_name
export PATH="$PATH:/Users/nagatadaisuke/flutter/bin" ## <- vim .zshrc or vim .bash_profile をコピーしてpathを設定する
# Run Flutter analyze
flutter analyze
result=$?
# Apply stashed changes back to the working directory
stash_entries=$(git stash list)
if [[ $stash_entries =~ $stash_name ]]; then
git stash pop -q
fi
# Exit if flutter analyze failed
[ $result -ne 0 ] && exit 1
exit 0
chmod +x .git/hooks/pre-push
#!/bin/sh
# Check if we're in a SourceTree environment
if [ -z "$STREPOSITORY" ]; then
# Not in SourceTree, set PATH manually
export PATH="/path/to/flutter/bin:$PATH"
fi
export PATH="$PATH:/Users/nagatadaisuke/flutter/bin" ## <- vim .zshrc or vim .bash_profile をコピーしてpathを設定する
# Run Flutter analyze
flutter analyze
if [ $? -ne 0 ]; then
echo "Flutter analyze found issues. Aborting push."
exit 1
fi
# No issues found, proceed with push
exit 0