From fb54ccc29ef84db56630e44636318cb2acdf0192 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Wed, 23 Jul 2008 08:20:55 -0500 Subject: [PATCH] Add support for locking branches. --- cbas/update | 1 + server/locked_branches | 0 server/preserved_branches | 1 + server/update-lock-check.rb | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 server/locked_branches create mode 100644 server/preserved_branches create mode 100755 server/update-lock-check.rb diff --git a/cbas/update b/cbas/update index a4a4374..02ed157 100755 --- a/cbas/update +++ b/cbas/update @@ -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 index 0000000..e69de29 diff --git a/server/preserved_branches b/server/preserved_branches new file mode 100644 index 0000000..2bf5ad0 --- /dev/null +++ b/server/preserved_branches @@ -0,0 +1 @@ +stable diff --git a/server/update-lock-check.rb b/server/update-lock-check.rb new file mode 100755 index 0000000..d08a3c2 --- /dev/null +++ b/server/update-lock-check.rb @@ -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) + -- 2.39.5