環境
- 建立 gitolite 環境:參考 Tsung 的「Linux 使用 Gitolite 架設 Git Server」 採用 gitolite 這個帳號直接管理 gitolite,沒有另外建立一個 git 的 linux user 帳號。
- gitolite 的 hooks 位在:/usr/share/gitolite/hooks/common
- 寄信通知大家的工具程式「post-receive-email」位在:/usr/share/doc/git/contrib/hooks/post-receive-email
方向
- 讓 gitolite 的 hook script 裡頭知道要去哪裡找到可以執行送信程式「post-receive-email」
$ sudo chmod a+x /usr/share/doc/git/contrib/hooks/post-receive-email $ sudo vim /usr/share/gitolite/hooks/common/post-receive $ sudo chmod a+x /usr/share/gitolite/hooks/common/post-receive在 /usr/share/gitolite/hooks/common/post-receive 中,原本是空的,可以輸入以下 script:
#!/bin/bash /usr/share/doc/git/contrib/hooks/post-receive-email
- 調整 .gitolite.rc 檔案內容(不然等一下設定 git config 參數在 gitolite.conf 的時候,gitolite 會不認識 config 參數)
$ sudo su gitolite $ vim .gitolite.rc # 然後找到「$GL_GITCONFIG_KEYS = "";」 # 改成「$GL_GITCONFIG_KEYS = ".*";」 $ gl-setup admin.pub
- 將 git config 參數設定在 gitolite-admin/conf/gitolite.conf 裡頭,然後 git push
repo testing # 在此以 testing 這個 repo 為範例 RW+ = @all # 你原本的權限設定 config hooks.mailinglist = "ernest@example.com, chiang@example.com" # 可以寄信給多個人 config hooks.envelopesender = git@example.com # 寄件者的信箱地址 email address of sender config hooks.emailprefix = "[testing] " # 信件主旨的開頭字串 config hooks.showrev = "git show -C %s; echo" # 原本只有列出有改動的檔案們,在此我改為列出有改動的檔案內容然後 git add, git commit, git push 到 git server 去。
- git push 後,在 git server 端,用 gitolite 這個 user 跑 gl-setup (讓 gitolite 幫我們將 config 和 hooks 灑進去各個 repository 中)
$ sudo su gitolite $ gl-setup admin.pub
到目前為止應該 hook 可以正常動作了 :)
參考參數:
(reference)
# Config # ------ # hooks.mailinglist # This is the list that all pushes will go to; leave it blank to not send # emails for every ref update. # hooks.announcelist # This is the list that all pushes of annotated tags will go to. Leave it # blank to default to the mailinglist field. The announce emails lists # the short log summary of the changes since the last annotated tag. # hooks.envelopesender # If set then the -f option is passed to sendmail to allow the envelope # sender address to be set # hooks.emailprefix # All emails have their subjects prefixed with this prefix, or "[SCM]" # if emailprefix is unset, to aid filtering # hooks.showrev # The shell command used to format each revision in the email, with # "%s" replaced with the commit id. Defaults to "git rev-list -1 # --pretty %s", displaying the commit id, author, date and log # message. To list full patches separated by a blank line, you # could set this to "git show -C %s; echo". # To list a gitweb/cgit URL *and* a full patch for each change set, use this: # "t=%s; printf 'http://.../?id=%%s' \$t; echo;echo; git show -C \$t; echo" # Be careful if "..." contains things that will be expanded by shell "eval" # or printf. # hooks.emailmaxlines # The maximum number of lines that should be included in the generated # email body. If not specified, there is no limit. # Lines beyond the limit are suppressed and counted, and a final # line is added indicating the number of suppressed lines. #
參考文件:
- 設定 Git Commit 更新 自動寄信通知 (Tsung, #git)
- hook propagation in gitolite (gitolite 官方文件, #但幫助不大)
- mirroring gitolite servers (gitolite 官方文件, #我在這參考 mirror 作法找到 hook 的接點)
- configuring gitolite's advanced features -- the .gitolite.rc file (gitolite 官方文件, #.rc 檔案設定方式參考)
- gitolite 的 hook… (gslin, #gitolite #很重要的 hint)
- How to setup post-receive-email Git hook with Gitolite (stackoverflow)
0 Comments:
Post a Comment