Skip to content

Instantly share code, notes, and snippets.

@huynguyencong
Created July 10, 2023 03:56
Show Gist options
  • Save huynguyencong/f8266cc4c4a4077646abe1dc957ad634 to your computer and use it in GitHub Desktop.
Save huynguyencong/f8266cc4c4a4077646abe1dc957ad634 to your computer and use it in GitHub Desktop.
Flutter project's githook
#!/usr/bin/env bash
# Adapted from https://gist.github.com/pgilad/5d7e4db725a906bd7aa7
# Make sure to add execute permissions using: chmod +x <file-name>
develop_branch="main"
current_branch="$(git rev-parse --abbrev-ref HEAD)"
# don't check commit messages on main development branch
[ "$current_branch" == "$develop_branch" ] && exit 0
# regex to validate in commit msg
commit_regex='^(\w{2,3}-\d+)(, )?(?:\w{2,3}-\d+)*: |^NOTICKET: |^WIP|merge'
error_msg="Aborting commit. Your commit message is not conforming to 'PRJCODE-1111: ', 'merge' or 'NOTICKET'."
if ! grep -iqE "$commit_regex" "$1"; then
echo "$error_msg" >&2
exit 1
fi
  • Create a .githooks directory in the root directory.
  • Add githook files to it.
  • Ask developers to run this command to use those githooks.
git config core.hooksPath .githooks
#!/bin/sh
# Make sure to add execute permissions using: chmod +x <file-name>
source ~/.zshrc
dart format lib/ test/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment