Widgets

設定 Gitolite 範圍中每個 repository 在每次收到 git push 之後就通知該 repository 相關人員,需要設定 hook 機制。但是 gitolite 和 git 的設定方式有些不同,尋覓許多文件後終於找到實作的方式成功 :)


環境
  • 建立 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.
#


參考文件:





0 Comments:

Post a Comment

 
Top