Git hook for le git post commit (# 123 good post)

I need to make sure that commit messages are something that legitimately still rejects. The commit message should look like "# 123 commit missing bracket"

I want to make sure it starts with hash, there is an integer (no 123a), and the message is at least 10 words.

Nice to have: the message will not be exactly the same in the line

I use this Trac plugin for a set of changes, it describes in more detail the format of the commit message http://trac-hacks.org/wiki/TracTicketChangelogPlugin

Thank,

+5
source share
3 answers

commit-msg :

#!/usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)

#starts with # then number, space, and at least 5 words no more than 200
$regex = /(^#[0-9]+ \W*(\w+(\W+|$)){5,200})/

if !$regex.match(message)
puts "Your message is not formatted correctly (example: #XXX at least 5 words)"
exit 1
end

http://fhopf.blogspot.com/2011/01/git-hook-for-redmine-messages.html

+5

pre-receive, , , - . , - :

#!/bin/sh
while read rev_old rev_new ref
do
    MALFORMED="$(git rev-list --oneline $rev_old..$rev_new | egrep -v '^[a-f0-9]+ #[0-9]+ ')"
    if [ x"$MALFORMED" != x ]
    then
        echo Some commits had a malformed subject line
        exit 1
    fi
done

( , ...)

+5

All Articles