From 3aec36d3a1a15d0f295ee2da60cf5a718203f4c9 Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Wed, 13 Aug 2008 23:03:13 -0500 Subject: [PATCH] Convert lock check over to using config properties. --- server/locked_branches | 11 ----- server/preserved_branches | 1 - server/update-lock-check.rb | 13 +++--- tests/t2900-server-update-lock-check.sh | 54 +++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 18 deletions(-) delete mode 100644 server/locked_branches delete mode 100644 server/preserved_branches create mode 100644 tests/t2900-server-update-lock-check.sh diff --git a/server/locked_branches b/server/locked_branches deleted file mode 100644 index 76824d6..0000000 --- a/server/locked_branches +++ /dev/null @@ -1,11 +0,0 @@ -direct_billing -enotify -movePremiumPeriod -fifo -online_claim_appeal -er_add_employee -vanderbilt_branding -hotfix_3671 -hotfix_3682 -hotfix_3684 -candidate_6.0 diff --git a/server/preserved_branches b/server/preserved_branches deleted file mode 100644 index 2bf5ad0..0000000 --- a/server/preserved_branches +++ /dev/null @@ -1 +0,0 @@ -stable diff --git a/server/update-lock-check.rb b/server/update-lock-check.rb index d08a3c2..aa577c2 100755 --- a/server/update-lock-check.rb +++ b/server/update-lock-check.rb @@ -15,19 +15,20 @@ def reject(message) 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 - locked_branches = IO::readlines(DATA_DIR + 'locked_branches').collect!(){|element| element.strip()} - if(locked_branches.include?(commit_branch)) - reject("Branch '#{commit_branch}' is locked.") + if(locked.include?(commit_branch)) + reject("Branch #{commit_branch} is locked.") end if(NEWREV =~ /^0{40}$/) # Branch deletion - preserved_branches = IO::readlines(DATA_DIR + 'preserved_branches').collect!(){|element| element.strip()} - if(preserved_branches.include?(commit_branch)) - reject("Branch '#{commit_branch}' cannot be deleted.") + if(preserved.include?(commit_branch)) + reject("Branch #{commit_branch} cannot be deleted.") end end end diff --git a/tests/t2900-server-update-lock-check.sh b/tests/t2900-server-update-lock-check.sh new file mode 100644 index 0000000..d45fa39 --- /dev/null +++ b/tests/t2900-server-update-lock-check.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +test_description='server update lock check' + +. ./test-lib.sh + +test_expect_success 'setup' ' + echo "setup" >a && + git add a && + git commit -m "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 fetch +' + +install_update_hook 'update-lock-check.rb' + +test_expect_success 'locked branch is rejected' ' + cd server && + git config hooks.update-lock-check.locked master && + cd .. && + + echo "$test_name" >a && + git commit -a -m "changed" && + ! git push 2>push.err && + cat push.err | grep "Branch master is locked" +' + +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 "$test_name" >a && + git commit -a -m "changed" && + ! git push 2>push.err && + cat push.err | grep "Branch master is locked" +' + +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 .. && + + ! git push origin :master 2>push.err && + cat push.err | grep "Branch master cannot be deleted" +' + +test_done + -- 2.39.5