Customizing Emacs for Git Commit Messages
(add-hook 'find-file-hook 'imp-git-hook)
will do the job nicely. Next up, we need to define this function to do something useful when run (indeed, failure to define it will result in an error when visiting all files).
(defun imp-git-hook ()
(when (string= (file-name-base buffer-file-name) "COMMIT_EDITMSG")
buffer-file-name is a local variable that has the full path name to the buffer, if any. file-name-base is like basename(1) in that it returns the name of the file without the extension, rather than its whole path.
But what is 'freebsd-git-setup'? It's a little function I wrote to set the fill column to 72 (I usually have it at 80, but that produces commit messages that are just a bit wide when git adds leading spaces) and adds a sponsorship tag to my commits:
(defun freebsd-git-setup ()
(setq fill-column 72)
(if (re-search-forward "^Sponsored by:" nil t)
if (re-search-forward "^\n#" nil t)
(replace-match "\nSponsored by:\t\tNetflix\n\n#")))))
But it only adds the sponsorship tag if one isn't there yet.
This is a proof-of-concept function. No doubt it will have to evolve over time. The project adds 'Differential Revision' tags as the last tag in a commit message because differential requires (required?) that. And it wouldn't be good to add this for non-FreeBSD commits, so I'll have to find a way to filter for that... But I thought this would be useful, if nothing else than to my future self as a roadmap for how to do things like this.