sjakubowski
sjakubowski

Reputation: 2943

New git hook setup in bare repository issues (no output/execution)

I can't seem to get any git hooks working on my setup.

sjakubowski@sjakubowski:~/Work/git$ mkdir hookstest
sjakubowski@sjakubowski:~/Work/git$ cd hookstest/
hookstest$ git init

Initialized empty Git repository in /home/sjakubowski/Work/git/hookstest/.git/

hookstest$ git commit -m "initial commit"

[master (root-commit) 82b95e0] initial commit
 0 files changed
 create mode 100644 testfile

hookstest$ touch .git/hooks/commit-msg
hookstest$ nano .git/hooks/commit-msg
hookstest$ cat .git/hooks/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

hookstest$ touch testfile2
hookstest$ git add testfile2
hookstest$ git commit -m "this message won't be blocked"
[master adea486] this message won't be blocked
 0 files changed
 create mode 100644 testfile2

What am I missing? Here is my configuration.

hookstest$ git --version
git version 1.7.9.5
hookstest$ ruby --version
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
hookstest$ git config --list
user.name=Sylvester Jakubowski
[email protected]
github.user=sjakubowski
github.token=XXXX
color.ui=true
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true

Upvotes: 0

Views: 207

Answers (1)

dunni
dunni

Reputation: 44535

The hook files must have set the executable bit (chmod +x), otherwise they can't be executed by Git.

Upvotes: 1

Related Questions