Skip to content

Instantly share code, notes, and snippets.

@ampersanda
Created April 20, 2020 14:37
Show Gist options
  • Save ampersanda/6dcac705ef614b3b7be85be90f9f2dd1 to your computer and use it in GitHub Desktop.
Save ampersanda/6dcac705ef614b3b7be85be90f9f2dd1 to your computer and use it in GitHub Desktop.
Dart analysis_options.yaml pre-push guard
#!/bin/bash
# Run to initialze pre-push configuration
rm -f .git/hooks/pre-push
cat >.git/hooks/pre-push <<EOL
# stash any unstaged changes
git stash -q --keep-index
# run Flutter analyze
if ! type "$PWD/fvm" > /dev/null; then
echo 'Using flutter'
flutter analyze
else
echo 'Using fvm'
./fvm analyze
fi
if [ $? -ne 0 ]; then
# unstash the unstashed changes
git stash pop -q
exit 1
fi
# unstash the unstashed changes
git stash pop -q
exit 0
EOL
chmod +x .git/hooks/pre-push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment