]> git.droids-corp.org - git-central.git/commitdiff
Convert lock check over to using config properties.
authorStephen Haberman <stephen@exigencecorp.com>
Thu, 14 Aug 2008 04:03:13 +0000 (23:03 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Thu, 14 Aug 2008 04:03:13 +0000 (23:03 -0500)
server/locked_branches [deleted file]
server/preserved_branches [deleted file]
server/update-lock-check.rb
tests/t2900-server-update-lock-check.sh [new file with mode: 0644]

diff --git a/server/locked_branches b/server/locked_branches
deleted file mode 100644 (file)
index 76824d6..0000000
+++ /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 (file)
index 2bf5ad0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-stable
index d08a3c2d4682cc4318d8bbdc7ac042d017a20d82..aa577c2f56555fab3a62e91f1ac2b4b106a32501 100755 (executable)
@@ -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 (file)
index 0000000..d45fa39
--- /dev/null
@@ -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
+