Skip to content
Snippets Groups Projects
Commit b9a6650b authored by Thomas Jürges's avatar Thomas Jürges
Browse files

ROADMT-103: Add git client side hooks

The user has to install one of the two client side hooks
him|herself.  There's no way this can be enforced.
parent 4cf3cf18
No related branches found
No related tags found
1 merge request!6Import cobalt2 into lofar4
#! /usr/bin/env ruby
message_file = ARGV[0]
message = File.read(message_file)
$regex = /^((fixes|task|story|issue)\s)?(#(\d+)|[a-zA-Z]+-(\d)+):/i
if !$regex.match(message)
STDERR.puts("[commit-msg hook] Your commit #{ rev } was rejected!\n"\
"[commit-msg hook] A commit message must start with a JIRA task ID,\n"\
" or \"task\", \"story\", \"issue\" or \"fixes\", followed by an issue ID.\n"\
"[commit-msg hook] For example: \"Task #42: Fixed bug\" or \"SW-22334: Fixed bug\"\n"\
"[commit-msg hook] Your commit message was: " + message)
exit 1
end
#! /usr/bin/env ruby
$regex = /^((fixes|task|story|issue)\s)?(#(\d+)|[a-zA-Z]+-(\d)+):/i
# Simple function, just for ease of testing
def parse_message(msg,re)
if not re.match(msg)
return false
else
return true
end
end
# enforced custom commit message format
def check_message_format
missed_revs = `git rev-list #{$rev_old}..#{$rev_new}`.split("\n")
missed_revs.each do |rev|
message = `git cat-file commit #{rev} | sed '1,/^$/d'`
if not parse_message(message,$regex)
STDERR.puts("[pre-receive hook] Your commit #{ rev } was rejected.")
STDERR.puts("[pre-receive hook] Commit message must start with a JIRA task ID,"\
" or \"Task\", \"Story\", \"Issue\" or \"Fixes\", followed by an issue ID.")
STDERR.puts("[pre-receive hook] For example: \"Task #42: Fixed bug\" or \"SW-22334: Fixed bug\"")
STDERR.puts("[pre-receive hook] Your commit message was: " +message)
exit 1
end
end
end
# The "main" method ... when executing this file:
# Only run this if the file itself is being executed
if __FILE__ == $0
$rev_old, $rev_new, $ref = STDIN.read.split(" ")
check_message_format
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment