From 5e1fb56a0dc4016b7f814e7122599cdaffe97605 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Tue, 11 Nov 2008 22:21:52 -0600 Subject: [PATCH] Go back to using flat files for locking but keep them in the repo-specific GIT_DIR. --- server/update-lock-check | 39 ++++++++++++++++++++++++++++++++ server/update-lock-check.rb | 37 ------------------------------ tests/t2900-update-lock-check.sh | 21 +++++++---------- 3 files changed, 47 insertions(+), 50 deletions(-) create mode 100644 server/update-lock-check delete mode 100755 server/update-lock-check.rb diff --git a/server/update-lock-check b/server/update-lock-check new file mode 100644 index 0000000..098dc16 --- /dev/null +++ b/server/update-lock-check @@ -0,0 +1,39 @@ +#!/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 + diff --git a/server/update-lock-check.rb b/server/update-lock-check.rb deleted file mode 100755 index aa577c2..0000000 --- a/server/update-lock-check.rb +++ /dev/null @@ -1,37 +0,0 @@ -#! /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) - diff --git a/tests/t2900-update-lock-check.sh b/tests/t2900-update-lock-check.sh index d45fa39..2a10ddc 100644 --- a/tests/t2900-update-lock-check.sh +++ b/tests/t2900-update-lock-check.sh @@ -11,17 +11,15 @@ test_expect_success 'setup' ' 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" && @@ -30,9 +28,8 @@ test_expect_success 'locked branch is rejected' ' ' 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" && @@ -41,10 +38,8 @@ test_expect_success 'locked branch is rejected with multiple branches set' ' ' 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" -- 2.39.5