--- /dev/null
+#!/bin/sh
+
+#
+# Checks $GIT_DIR/locked and $GIT_DIR/preserved for branches that cannot be
+# touched.
+#
+
+. $(dirname $0)/functions
+
+refname=$1
+oldrev=$2
+newrev=$3
+
+# We only care about branches
+case "$refname" in
+ refs/heads/*)
+ short_refname=${refname##refs/heads/}
+ ;;
+ *)
+ exit 0
+ ;;
+esac
+
+if test -f "$GIT_DIR/locked" ; then
+ grep $short_refname "$GIT_DIR/locked"
+ if [ $? -eq 0 ] ; then
+ display_error_message "Branch $short_refname is locked"
+ exit 1
+ fi
+fi
+
+if test -f "$GIT_DIR/preserved" ; then
+ grep $short_refname "$GIT_DIR/preserved"
+ if [ $? -eq 0 ] ; then
+ display_error_message "Branch $short_refname cannot be deleted"
+ exit 1
+ fi
+fi
+
+++ /dev/null
-#! /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
-
-locked = `git config hooks.update-lock-check.locked`.split(' ').collect { |element| element.strip() }
-preserved = `git config hooks.update-lock-check.preserved`.split(' ').collect { |element| element.strip() }
-
-if(REFNAME =~ /^refs\/heads\/(.+)$/)
- # Branch commit
- commit_branch = $1
- if(locked.include?(commit_branch))
- reject("Branch #{commit_branch} is locked.")
- end
-
- if(NEWREV =~ /^0{40}$/)
- # Branch deletion
- if(preserved.include?(commit_branch))
- reject("Branch #{commit_branch} cannot be deleted.")
- end
- end
-end
-
-Kernel::exit(0)
-
git clone ./. server &&
rm -fr server/.git/hooks &&
git remote add origin ./server &&
- git config --add branch.master.remote origin &&
- git config --add branch.master.merge refs/heads/master &&
+ git config branch.master.remote origin &&
+ git config branch.master.merge refs/heads/master &&
git fetch
'
-install_update_hook 'update-lock-check.rb'
+install_update_hook 'update-lock-check'
test_expect_success 'locked branch is rejected' '
- cd server &&
- git config hooks.update-lock-check.locked master &&
- cd .. &&
+ echo master >> server/.git/locked &&
echo "$test_name" >a &&
git commit -a -m "changed" &&
'
test_expect_success 'locked branch is rejected with multiple branches set' '
- cd server &&
- git config hooks.update-lock-check.locked "foo bar master" &&
- cd .. &&
+ echo foo >> server/.git/locked &&
+ echo bar >> server/.git/locked &&
echo "$test_name" >a &&
git commit -a -m "changed" &&
'
test_expect_success 'preserved branch cannot be deleted' '
- cd server &&
- git config hooks.update-lock-check.locked "" &&
- git config hooks.update-lock-check.preserved master &&
- cd .. &&
+ echo > server/.git/locked &&
+ echo master > server/.git/preserved &&
! git push origin :master 2>push.err &&
cat push.err | grep "Branch master cannot be deleted"