aa577c2f56555fab3a62e91f1ac2b4b106a32501
[git-central.git] / server / update-lock-check.rb
1 #! /usr/bin/ruby
2
3 REFNAME = ARGV[0]
4 OLDREV = ARGV[1]
5 NEWREV = ARGV[2]
6
7 DATA_DIR = '/srv/git/hooks/server/'
8
9 def reject(message)
10         $stdout.puts "---------------------------------------------------------"
11         $stdout.puts "Commit #{NEWREV} rejected:"
12         $stdout.puts "\t#{message}"
13         $stdout.puts "---------------------------------------------------------"
14         $stdout.flush()
15         Kernel::exit(1)
16 end
17
18 locked = `git config hooks.update-lock-check.locked`.split(' ').collect { |element| element.strip() }
19 preserved = `git config hooks.update-lock-check.preserved`.split(' ').collect { |element| element.strip() }
20
21 if(REFNAME =~ /^refs\/heads\/(.+)$/)
22         # Branch commit
23         commit_branch = $1
24         if(locked.include?(commit_branch))
25                 reject("Branch #{commit_branch} is locked.")
26         end
27
28         if(NEWREV =~ /^0{40}$/)
29                 # Branch deletion
30                 if(preserved.include?(commit_branch))
31                         reject("Branch #{commit_branch} cannot be deleted.")
32                 end
33         end
34 end
35
36 Kernel::exit(0)
37