Commit 56fc53e8d870b70ca66332daeb6da39ab0eb5ce7

Authored by Ariejan de Vroom
1 parent bc0155fb

Automatically write hooks when updating a repository.

Showing 1 changed file with 9 additions and 2 deletions   Show diff stats
app/models/repository.rb
@@ -31,8 +31,13 @@ class Repository @@ -31,8 +31,13 @@ class Repository
31 project.id 31 project.id
32 end 32 end
33 33
34 - # repo.update_hook('post-receive', File.read('some-hook'))  
35 - def update_hook(name, content) 34 + def write_hooks
  35 + %w(post-receive).each do |hook|
  36 + write_hook(hook, File.read(File.join(Rails.root, 'lib', "#{hook}-hook")))
  37 + end
  38 + end
  39 +
  40 + def write_hook(name, content)
36 hook_file = File.join(project.path_to_repo, 'hooks', name) 41 hook_file = File.join(project.path_to_repo, 'hooks', name)
37 42
38 File.open(hook_file, 'w') do |f| 43 File.open(hook_file, 'w') do |f|
@@ -58,6 +63,8 @@ class Repository @@ -58,6 +63,8 @@ class Repository
58 Gitlabhq::GitHost.system.new.configure do |c| 63 Gitlabhq::GitHost.system.new.configure do |c|
59 c.update_project(path, project) 64 c.update_project(path, project)
60 end 65 end
  66 +
  67 + write_hooks
61 end 68 end
62 69
63 def destroy_repository 70 def destroy_repository