Make commit message function customizable

This commit is contained in:
Yegor Timoshenko 2017-08-06 23:05:15 +00:00
parent 2c8197e5d7
commit f488678f85

View file

@ -58,6 +58,12 @@ If non-nil a git push will be executed after each commit."
:group 'git-auto-commit-mode
:type 'string)
(defcustom gac-commit-message-function
(lambda (path) (if gac-ask-for-summary-p (read-string "Summary:" nil nil path) path))
"Return a Git commit message based on PATH to be commited."
:group 'git-auto-commit-mode
:type 'function)
(defun gac-relative-file-name (filename)
"Find the path to FILENAME relative to the git directory."
(let* ((git-dir
@ -100,21 +106,12 @@ STRING is the output line from PROC."
"Report PROC change to STATUS."
(message "git %s" (substring status 0 -1)))
(defun gac--commit-msg (filename)
"Get a commit message.
Default to FILENAME."
(let ((relative-filename (gac-relative-file-name filename)))
(if (not gac-ask-for-summary-p)
relative-filename
(read-string "Summary: " nil nil relative-filename))))
(defun gac-commit ()
"Commit the current buffer's file to git."
(let* ((buffer-file (buffer-file-name))
(filename (convert-standard-filename
(file-name-nondirectory buffer-file)))
(commit-msg (gac--commit-msg buffer-file))
(commit-msg (funcall gac-commit-message-function (gac-relative-file-name buffer-file)))
(default-directory (file-name-directory buffer-file)))
(shell-command
(concat "git add " (shell-quote-argument filename)