X

設定 Git Commit 更新 自動寄信通知

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 更新自動寄信通知的設定步驟

  1. chmod a+x /usr/share/doc/git-core/contrib/hooks/post-receive-email
  2. ln -sf /usr/share/doc/git-core/contrib/hooks/post-receive-email /var/cache/git/project.git/hooks/post-receive
  3. 到此 Commit 變更就會自動寄信了, 不過, 要寄去哪邊, 信件標題等等該怎麼設定, 於下述設定.

設定 要寄到哪個 Email 步驟 (git config hooks.mailinglist)

  1. cd /var/cache/git/project.git
  2. git config --add hooks.mailinglist "project-commit@lists.example.com"
  3. 到此即可.
  4. 檢查: vim config # 會看到下述

    [hooks]
    mailinglist = project-commit@lists.example.com

設定信件標題的 Prefix (git config hooks.emailprefix "[prefix-title]")

  1. cd /var/cache/git/project.git
  2. git config hooks.emailprefix "[project-name]"
  3. 到此即可.
  4. 檢查: 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 沒有設定, 設定步驟如下:

  1. vim /var/cache/git/project.git/description

    Unnamed repository; edit this file 'description' to name the repository.

  2. 改成

    Project-name

  3. 註: 此 UNNAMED PROJECT 得判斷方法為: projectdesc=$(sed -ne '1p' "$GIT_DIR/description")

相關網頁

Tsung: 對新奇的事物都很有興趣, 喜歡簡單的東西, 過簡單的生活.
Related Post