Git 有任何 Commit / Push / 更新, 想要自動寄信通知, 要如何設定?
前置準備 - 環境
- 系統: Debian / Ubuntu Linux
- Repository Path: /var/cache/git/project.git # /path/to/your/repository.git
- 變更需寄送到的 Email: project-commit@lists.example.com
Git 寄信所需的 hook 與 script 如下:
- /var/cache/git/project.git/hooks/post-receive.sample
- /usr/share/doc/git-core/contrib/hooks/post-receive-email
Git 更新自動寄信通知的設定步驟
- chmod a+x /usr/share/doc/git-core/contrib/hooks/post-receive-email
- ln -sf /usr/share/doc/git-core/contrib/hooks/post-receive-email /var/cache/git/project.git/hooks/post-receive
- 到此 Commit 變更就會自動寄信了, 不過, 要寄去哪邊, 信件標題等等該怎麼設定, 於下述設定.
設定 要寄到哪個 Email 步驟 (git config hooks.mailinglist)
- cd /var/cache/git/project.git
- git config --add hooks.mailinglist "project-commit@lists.example.com"
- 到此即可.
- 檢查: vim config # 會看到下述
[hooks]
mailinglist = project-commit@lists.example.com
設定信件標題的 Prefix (git config hooks.emailprefix "[prefix-title]")
- cd /var/cache/git/project.git
- git config hooks.emailprefix "[project-name]"
- 到此即可.
- 檢查: vim config # 會看到下述
[hooks]
mailinglist = project-commit@lists.example.com
emailprefix = [project_name]
註: /usr/share/doc/git-core/contrib/hooks/post-receive-email 裡面有更多參數可以增加, 如下述:
- hooks.mailinglist
- hooks.announcelist
- hooks.envelopesender
- hooks.emailprefix
- hooks.showrev
信件標題出現 "[project_name] UNNAMED PROJECT branch, master, updated." 設定
"UNNAMED" 代表 Project description 沒有設定, 設定步驟如下:
- vim /var/cache/git/project.git/description
Unnamed repository; edit this file 'description' to name the repository.
- 改成
Project-name
- 註: 此 UNNAMED PROJECT 得判斷方法為: projectdesc=$(sed -ne '1p' "$GIT_DIR/description")