Permalink
Browse files

Go back to using flat files for locking but keep them in the repo-spe…

…cific GIT_DIR.
  • Loading branch information...
1 parent be4fac0 commit 5e1fb56a0dc4016b7f814e7122599cdaffe97605 @stephenh committed Nov 12, 2008
Showing with 47 additions and 50 deletions.
  1. +39 −0 server/update-lock-check
  2. +0 −37 server/update-lock-check.rb
  3. +8 −13 tests/t2900-update-lock-check.sh
@@ -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
+
@@ -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)
-
@@ -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"

0 comments on commit 5e1fb56

Please sign in to comment.