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
--- /dev/null
+#!/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
+