Skip to content

Commit

Permalink
Go back to using flat files for locking but keep them in the repo-spe…
Browse files Browse the repository at this point in the history
…cific GIT_DIR.
  • Loading branch information
Stephen Haberman committed Nov 12, 2008
1 parent be4fac0 commit 5e1fb56
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 50 deletions.
39 changes: 39 additions & 0 deletions 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

37 changes: 0 additions & 37 deletions server/update-lock-check.rb

This file was deleted.

21 changes: 8 additions & 13 deletions tests/t2900-update-lock-check.sh
Expand Up @@ -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" &&
Expand All @@ -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" &&
Expand All @@ -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"
Expand Down

0 comments on commit 5e1fb56

Please sign in to comment.