]> git.droids-corp.org - git-central.git/commitdiff
Add support for locking branches.
authorStephen Haberman <shaberman@payflex.com>
Wed, 23 Jul 2008 13:20:55 +0000 (08:20 -0500)
committerStephen Haberman <shaberman@payflex.com>
Wed, 23 Jul 2008 13:20:55 +0000 (08:20 -0500)
cbas/update
server/locked_branches [new file with mode: 0644]
server/preserved_branches [new file with mode: 0644]
server/update-lock-check.rb [new file with mode: 0755]

index a4a4374673380b33380ffbb480c9e314ef8a8a33..02ed15751ae98060081eb7b1a4e03679893a3a72 100755 (executable)
@@ -4,6 +4,7 @@ refname="$1"
 oldrev="$2"
 newrev="$3"
 
+ruby /srv/git/hooks/server/update-lock-check.rb "$refname" "$oldrev" "$newrev" &&
 sh /srv/git/hooks/server/update-trac "$refname" "$oldrev" "$newrev" &&
 sh /srv/git/hooks/server/update-allow-tags-branches "$refname" "$oldrev" "$newrev" &&
 sh /srv/git/hooks/server/update-prefer-rebase "$refname" "$oldrev" "$newrev" &&
diff --git a/server/locked_branches b/server/locked_branches
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/server/preserved_branches b/server/preserved_branches
new file mode 100644 (file)
index 0000000..2bf5ad0
--- /dev/null
@@ -0,0 +1 @@
+stable
diff --git a/server/update-lock-check.rb b/server/update-lock-check.rb
new file mode 100755 (executable)
index 0000000..d08a3c2
--- /dev/null
@@ -0,0 +1,36 @@
+#! /usr/bin/ruby
+
+REFNAME = ARGV[0]
+OLDREV = ARGV[1]
+NEWREV = ARGV[2]
+
+DATA_DIR = '/srv/git/hooks/server/'
+
+def reject(message)
+       $stdout.puts "---------------------------------------------------------"
+       $stdout.puts "Commit #{NEWREV} rejected:"
+       $stdout.puts "\t#{message}"
+       $stdout.puts "---------------------------------------------------------"
+       $stdout.flush()
+       Kernel::exit(1)
+end
+
+if(REFNAME =~ /^refs\/heads\/(.+)$/)
+       # Branch commit
+       commit_branch = $1
+       locked_branches = IO::readlines(DATA_DIR + 'locked_branches').collect!(){|element| element.strip()}
+       if(locked_branches.include?(commit_branch))
+               reject("Branch '#{commit_branch}' is locked.")
+       end
+
+       if(NEWREV =~ /^0{40}$/)
+               # Branch deletion
+               preserved_branches = IO::readlines(DATA_DIR + 'preserved_branches').collect!(){|element| element.strip()}
+               if(preserved_branches.include?(commit_branch))
+                       reject("Branch '#{commit_branch}' cannot be deleted.")
+               end
+       end
+end
+
+Kernel::exit(0)
+