Skip to content

Instantly share code, notes, and snippets.

@fizzyade
Last active October 12, 2019 12:21
Show Gist options
  • Save fizzyade/fd59e86fdf1e9f12f408e877a882edc1 to your computer and use it in GitHub Desktop.
Save fizzyade/fd59e86fdf1e9f12f408e877a882edc1 to your computer and use it in GitHub Desktop.
A simple GIT commit-msg hook that conforms to the conventional commits style
#!/usr/bin/env python
# Copyright (C) 2019 Adrian Carpenter
#
# Simple GIT commit-msg hook that conforms to the conventional commits style.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import re
import sys
line = open(sys.argv[1]).readline().rstrip("\r\n")
valid = re.match("^(wip|repo|feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?: [a-z].{1,50}[^\. ]$", line)
if valid:
sys.exit(0)
print("the commit message was not formatted correctly.")
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment