Skip to content

Instantly share code, notes, and snippets.

@pogin503
Created December 5, 2012 05:04
Show Gist options
  • Save pogin503/4212441 to your computer and use it in GitHub Desktop.
Save pogin503/4212441 to your computer and use it in GitHub Desktop.
test-post-receive.sh
#!/bin/sh
# rm ~/foo -rf
function sep (){
echo "==================="
echo ""
echo "==================="
}
# テスト用リポジトリを作る (~/foo/test )
mkdir foo
cd ~/foo && pwd
mkdir test
cd test/ && pwd
git init
touch test.txt
echo "foo" >> test.txt
git add . && git commit -m "test commit"
sep
# テスト用リモートを作る (~/foo/repo.git)
cd ~/foo && pwd
mkdir repo.git
cd repo.git && pwd
git init --bare #リモートリポジトリを作るためにbareリポジトリを作る
sep
cd ~/foo/test && pwd
git push ~/foo/repo.git master
sep
# フックを設定する (~/receive)
cd ~/foo && pwd
git clone ~/foo/repo.git receive # cloneのときreceiveというディレクトリ名でクローンする
cd repo.git/hooks/ && pwd
{
echo "#!/bin/sh"
echo ""
echo "# . /home/username/foo/repo.git/hooks/post-receive"
echo 'echo "test post-receive"'
echo "pwd"
echo "cd ~/foo/receive # post-receiveが実行されるときはrepo.git/にいる"
echo "pwd"
echo "git --git-dir=.git pull ../repo.git master"
} > post-receive
# post-receiveはchmodで実行権限を与えておかないと実行されない
chmod +x post-receive
sep
# post-receiveが動くかの確認
cd ~/foo/test && pwd
echo "test" >> test.txt && git add . && git commit -m "test commit" && git push ../repo.git/ master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment