-
Create
.githooks/
folder in the source root. -
Change the hooks folder to be .githooks, run:
git config core.hooksPath .githooks/
-
Create the
pre-commit
andpre-push
file without format inside.githooks
folder. -
Inside
pre-commit
file, put this:#!/usr/bin/env bash printf "\e[36;1m%s\e[0m\n" 'Pre-commit hook started' #Flutter format printf "\e[33;1m%s\e[0m\n" 'Running the Flutter formatter' flutter format . printf "\e[32;1m%s\e[0m\n" 'Finished running the Flutter formatter' printf "\e[36;1m%s\e[0m\n" 'Pre-commit hook finished'
-
Inside
pre-push
file, put this:#!/usr/bin/env bash #Check if exist some file(s) modified that have not been committed if [[ `git status --porcelain` ]]; then printf "\e[31;1m%s\e[0m\n" 'This script needs to run against committed code only. Please commit or stash you changes.' exit 1 fi printf "\e[36;1m%s\e[0m\n" 'Pre-push hook started' #Flutter analyzer 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[32;1m%s\e[0m\n" 'Finished running the Flutter analyzer' #Flutter test 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[32;1m%s\e[0m\n" 'Finished running unit tests' printf "\e[36;1m%s\e[0m\n" 'Pre-push hook finished'
-
After this, now we need make the
pre-commit
andpre-push
files executable:cd .githooks && chmod +x pre-commit && chmod +x pre-push && cd ..
-
Now
if youcommit
orpush
some code, willrun/execute
thishooks
: -
Commit
: -
Push
:
-
Notifications
You must be signed in to change notification settings - Fork 0
samuelematias/flutter-git-hooks
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
 |  | |||
Repository files navigation
About
An example project on how to implement git hooks in flutter project 🎣
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published