]> git.droids-corp.org - git-central.git/commitdiff
We can check hooks into gitconfig as well.
authorStephen Haberman <stephen@exigencecorp.com>
Tue, 19 Aug 2008 22:00:50 +0000 (17:00 -0500)
committerStephen Haberman <stephen@exigencecorp.com>
Tue, 19 Aug 2008 22:00:50 +0000 (17:00 -0500)
server/post-receive-git-config
tests/t2801-server-post-receive-git-config-hooks.sh [new file with mode: 0644]

index 2936718f731ccd95b5190a62e28117bc937b73d8..c80322ad096f1c54bb039d8f4d40060a467d5552 100644 (file)
@@ -2,7 +2,7 @@
 
 while read oldrev newrev refname ; do
        if [ "$refname" == "refs/heads/gitconfig" ] ; then
-               config_hash=$(git ls-tree $newrev | grep config | gawk '{print $3}')
+               config_hash=$(git ls-tree $newrev | grep config | grep -oP '\w{40}')
                if [[ "$config_hash" != "" ]] ; then
                        git cat-file blob "$config_hash" | while read line ; do
                                key="${line%=*}"
@@ -10,6 +10,14 @@ while read oldrev newrev refname ; do
                                git config "${key}" "${value}"
                        done
                fi
+
+               hooks_hash=$(git ls-tree $newrev | grep hooks | grep -oP '\w{40}')
+               if [[ "$hooks_hash" != "" ]] ; then
+                       git ls-tree "$hooks_hash" | while read mode type file_hash file_name ; do
+                               echo "Installing $file_name"
+                               git cat-file blob "$file_hash" > "hooks/$file_name"
+                       done
+               fi
        fi
 done
 
diff --git a/tests/t2801-server-post-receive-git-config-hooks.sh b/tests/t2801-server-post-receive-git-config-hooks.sh
new file mode 100644 (file)
index 0000000..e0c0057
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+test_description='server update git config'
+
+. ./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
+'
+
+install_post_receive_hook 'post-receive-git-config'
+
+test_expect_success 'adding hook' '
+       ls server/.git/hooks | grep post-receive &&
+       ../../scripts/make-gitconfig-branch &&
+       git checkout gitconfig &&
+
+       mkdir hooks &&
+       cd hooks &&
+       echo "#!/bin/sh" > post-receive &&
+       echo "../../../../server/post-receive-git-config" >> post-receive &&
+       echo "echo barbar" >> post-receive &&
+       echo "#!/bin/sh" > update  &&
+       echo "echo foofoo" >> update &&
+       git add post-receive &&
+       git add update &&
+       git commit -m "added post-receive and update" &&
+       git push origin gitconfig &&
+       cd .. &&
+
+       cat server/.git/hooks/post-receive | grep barbar &&
+       cat server/.git/hooks/update | grep foofoo
+'
+
+test_expect_success 'changing hook' '
+       echo "#!/bin/sh" > hooks/update  &&
+       echo "echo lala" >> hooks/update &&
+       git commit -a -m "changed update" &&
+       git push origin gitconfig &&
+
+       cat server/.git/hooks/post-receive | grep barbar &&
+       ! cat server/.git/hooks/update | grep barbar &&
+       cat server/.git/hooks/update | grep lala
+'
+
+test_expect_success 'removing hook does not work' '
+       git rm hooks/update &&
+       git commit -m "removed update" &&
+       git push origin gitconfig &&
+
+       ls server/.git/hooks | grep post-receive
+       ls server/.git/hooks | grep update
+'
+
+test_done
+