From 2681a4632cea45e05f24357941a811979c8c3f8c Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Tue, 19 Aug 2008 17:00:50 -0500 Subject: [PATCH] We can check hooks into gitconfig as well. --- server/post-receive-git-config | 10 ++- ...01-server-post-receive-git-config-hooks.sh | 61 +++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/t2801-server-post-receive-git-config-hooks.sh diff --git a/server/post-receive-git-config b/server/post-receive-git-config index 2936718..c80322a 100644 --- a/server/post-receive-git-config +++ b/server/post-receive-git-config @@ -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 index 0000000..e0c0057 --- /dev/null +++ b/tests/t2801-server-post-receive-git-config-hooks.sh @@ -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 + -- 2.39.5