无法自定义git commit-msg钩子

时间:2014-06-09 13:46:23

标签: git ubuntu

我正在尝试自定义git commit-msg挂钩,以便在提交代码之前检查特定的字符串格式。

但由于某种原因它无法正常工作,它会出现以下错误:

.git/hooks/commit-msg: 26: .git/hooks/commit-msg: message_file: not found
.git/hooks/commit-msg: 27: .git/hooks/commit-msg: Syntax error: "(" unexpected

用.git / hooks / commit-msg编写的代码:

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

$regex = /^TEST/

if !$regex.match(message)
  puts "[POLICY] Your message is not formatted correctly"
  exit 1
end

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

得到了修复。 我正在使用:

#!/bin/sh 

替换为:

#!/usr/bin/env ruby

它就像一个魅力。

相关问题