]> git.droids-corp.org - git-central.git/commitdiff
Go back to using flat files for locking but keep them in the repo-specific GIT_DIR.
authorStephen Haberman <stephen@exigencecorp.com>
Wed, 12 Nov 2008 04:21:52 +0000 (22:21 -0600)
committerStephen Haberman <stephen@exigencecorp.com>
Wed, 12 Nov 2008 04:21:52 +0000 (22:21 -0600)
server/update-lock-check [new file with mode: 0644]
server/update-lock-check.rb [deleted file]
tests/t2900-update-lock-check.sh

diff --git a/server/update-lock-check b/server/update-lock-check
new file mode 100644 (file)
index 0000000..098dc16
--- /dev/null
@@ -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 (executable)
index aa577c2..0000000
+++ /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)
-
index d45fa39bc36c95c3336326c78136d64801f3c4db..2a10ddc5703b05672146bc6d03bb2972eceb64c6 100644 (file)
@@ -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"