如何在gitlab中定义全局gitignore,或将其实现为全局预接收挂钩?

时间:2017-09-22 11:57:15

标签: ruby git gitlab hook

在ruby钩子中,我需要检查staged file format并限制提交,如果提交有.exe.dll文件。我有了在ruby git diff --cached --name-only --diff-filter=ACM中获取文件列表的想法,但我没有在ruby脚本中使用该行,因为我是ruby脚本的新手。

#!/usr/bin/env ruby

 Dir[git diff --cached --name-only --diff-filter=ACM].any? do |f|
     %w|.txt .pdf .dll|.include?(File.extname(f))
       puts "Your commit have exe or dll file. Kindly remove the file an$
     exit 0
  end

我知道如果钩子返回零意味着它通过了测试,或者它失败了条件。当我运行git push命令时,它显示以下异常。

  

remote:hooks / pre-receive:16:in require_relative': /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_ignore_binary.rb:3: syntax error, unexpected unary-, expecting keyword_do or '{' or '(' (SyntaxError) remote: Dir[git diff --cached --name-only --diff-filter=ACM].any? do |f| remote: ^ remote: /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_ignore_binary.rb:3: syntax error, unexpected unary-, expecting keyword_do or '{' or '(' remote: Dir[git diff --cached --name-only --diff-filter=ACM].any? do |f| remote: ^ remote: /opt/gitlab/embedded/service/gitlab-shell/lib/gitlab_ignore_binary.rb:3: syntax error, unexpected ']', expecting end-of-input remote: Dir[git diff --cached --name-only --diff-filter=ACM].any? do |f| remote: ^ remote: from hooks/pre-receive:16:in'

可以帮助任何帮助。

更新

有没有办法手动更新gitignore

0 个答案:

没有答案