Commit c9470f5c authored by Valery Sizov's avatar Valery Sizov

Ability to block commits with certain filenames

parent da86eace
...@@ -28,6 +28,6 @@ class Projects::GitHooksController < Projects::ApplicationController ...@@ -28,6 +28,6 @@ class Projects::GitHooksController < Projects::ApplicationController
# Only allow a trusted parameter "white list" through. # Only allow a trusted parameter "white list" through.
def git_hook_params def git_hook_params
params.require(:git_hook).permit(:deny_delete_tag, :delete_branch_regex, params.require(:git_hook).permit(:deny_delete_tag, :delete_branch_regex,
:commit_message_regex, :force_push_regex, :author_email_regex, :member_check) :commit_message_regex, :force_push_regex, :author_email_regex, :member_check, :file_name_regex)
end end
end end
...@@ -15,6 +15,6 @@ class GitHook < ActiveRecord::Base ...@@ -15,6 +15,6 @@ class GitHook < ActiveRecord::Base
end end
def commit_validation? def commit_validation?
commit_message_regex.present? || author_email_regex.present? || member_check commit_message_regex.present? || author_email_regex.present? || member_check || file_name_regex.present?
end end
end end
...@@ -63,6 +63,16 @@ ...@@ -63,6 +63,16 @@
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html' = link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed. to be pushed.
If this field is empty it allows any email. If this field is empty it allows any email.
.form-group
= f.label :file_name_regex, "Prohibited file names", class: 'control-label'
.col-sm-10
= f.text_field :file_name_regex, class: "form-control", placeholder: 'Example: (jar|exe)$'
%p.hint
All commited filenames must not match this
= link_to 'Ruby regular expression', 'http://www.ruby-doc.org/core-2.1.1/Regexp.html'
to be pushed.
If this field is empty it allows any filenames.
.form-actions .form-actions
= f.submit "Save Git hooks", class: "btn btn-create" = f.submit "Save Git hooks", class: "btn btn-create"
class AddFileNameRegexToGitHooks < ActiveRecord::Migration
def change
add_column :git_hooks, :file_name_regex, :string
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20141030133853) do ActiveRecord::Schema.define(version: 20141103160516) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -93,6 +93,7 @@ ActiveRecord::Schema.define(version: 20141030133853) do ...@@ -93,6 +93,7 @@ ActiveRecord::Schema.define(version: 20141030133853) do
t.datetime "updated_at" t.datetime "updated_at"
t.string "author_email_regex" t.string "author_email_regex"
t.boolean "member_check", default: false, null: false t.boolean "member_check", default: false, null: false
t.string "file_name_regex"
end end
create_table "issues", force: true do |t| create_table "issues", force: true do |t|
......
...@@ -128,6 +128,14 @@ module Gitlab ...@@ -128,6 +128,14 @@ module Gitlab
return false unless User.existing_member?(commit.committer_email) return false unless User.existing_member?(commit.committer_email)
end end
end end
if git_hook.file_name_regex.present?
commit.diffs.each do |diff|
if diff.renamed_file || diff.new_file
return false if diff.new_path =~ Regexp.new(git_hook.file_name_regex)
end
end
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment