0

我似乎无法在我的设置上使用任何 git 挂钩。

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

我错过了什么?这是我的配置。

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
user.email=XXXX@gmail.com
github.user=sjakubowski
github.token=XXXX
color.ui=true
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
4

1 回答 1

1

钩子文件必须设置了可执行位(chmod +x),否则它们不能被 Git 执行。

于 2012-11-22T21:26:13.440 回答