How do I define a global gitignore, or implement it as a global pre-receive hook, in gitlab?

时光毁灭记忆、已成空白 提交于 2019-12-24 19:15:05

问题


In the ruby hook, I need to check the staged file format and restrict the commit, If the commit have .exe or .dll file. I got the idea to get the file list in ruby git diff --cached --name-only --diff-filter=ACM, But I failed to use the line in ruby script because I am newbie for ruby script.

#!/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

I know If the hook return zero meant it passed the test, Or else it failed the condition. When I run the git push command means, It shows below exception.

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'

Any helps can be apriciated.

Update:

Is there any way to update the gitignore manually?

来源:https://stackoverflow.com/questions/46364247/how-do-i-define-a-global-gitignore-or-implement-it-as-a-global-pre-receive-hook

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!