From: Stephen Haberman Date: Thu, 14 Aug 2008 16:21:58 +0000 (-0500) Subject: Convert git config over to a post receive script. X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=25888636ae3eb414f0c08b9df01bff17e448f0d5;p=git-central.git Convert git config over to a post receive script. --- diff --git a/cbas/post-receive b/cbas/post-receive index 19824c1..8c24392 100755 --- a/cbas/post-receive +++ b/cbas/post-receive @@ -11,4 +11,5 @@ done echo -n "$input" | sh /srv/git/hooks/server/post-receive-email echo -n "$input" | sh /srv/git/hooks/server/post-receive-trac +echo -n "$input" | sh /srv/git/hooks/server/post-receive-git-config diff --git a/server/post-receive-git-config b/server/post-receive-git-config new file mode 100644 index 0000000..2936718 --- /dev/null +++ b/server/post-receive-git-config @@ -0,0 +1,15 @@ +#!/bin/sh + +while read oldrev newrev refname ; do + if [ "$refname" == "refs/heads/gitconfig" ] ; then + config_hash=$(git ls-tree $newrev | grep config | gawk '{print $3}') + if [[ "$config_hash" != "" ]] ; then + git cat-file blob "$config_hash" | while read line ; do + key="${line%=*}" + value="${line#*=}" + git config "${key}" "${value}" + done + fi + fi +done + diff --git a/server/update-git-config b/server/update-git-config deleted file mode 100644 index 30b814b..0000000 --- a/server/update-git-config +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -refname="$1" -oldrev="$2" -newrev="$3" - -if [ "$refname" != "refs/heads/gitconfig" ] ; then - exit 0 -fi - -config_hash=$(git ls-tree $newrev | grep config | gawk '{print $3}') -if [[ "$config_hash" != "" ]] ; then - git cat-file blob "$config_hash" | while read line ; do - key="${line%=*}" - value="${line#*=}" - git config "${key}" "${value}" - done -fi - diff --git a/tests/t2800-server-post-receive-git-config.sh b/tests/t2800-server-post-receive-git-config.sh new file mode 100644 index 0000000..2adbd6e --- /dev/null +++ b/tests/t2800-server-post-receive-git-config.sh @@ -0,0 +1,38 @@ +#!/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 && + git config --add branch.master.remote origin && + git config --add branch.master.merge refs/heads/master && + git fetch +' + +install_post_receive_hook 'post-receive-git-config' + +test_expect_success 'pushing initial value works' ' + cd server && + ! git config --list | grep foo && + cd .. && + + ../../scripts/make-gitconfig-branch.sh && + git checkout gitconfig && + echo "foo.foo=bar" > config && + git commit -a -m "Set foo.foo=bar." + git push origin gitconfig + + cd server && + git config --list | grep foo && + cd .. +' + +test_done + diff --git a/tests/t2800-server-update-git-config.sh b/tests/t2800-server-update-git-config.sh deleted file mode 100644 index d73df30..0000000 --- a/tests/t2800-server-update-git-config.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/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 && - git config --add branch.master.remote origin && - git config --add branch.master.merge refs/heads/master && - git fetch -' - -install_update_hook 'update-git-config' - -test_expect_success 'pushing initial value works' ' - cd server && - ! git config --list | grep foo && - cd .. && - - ../../scripts/make-gitconfig-branch.sh && - git checkout gitconfig && - echo "foo.foo=bar" > config && - git commit -a -m "Set foo.foo=bar." - git push origin gitconfig - - cd server && - git config --list | grep foo && - cd .. -' - -test_done -