VC: New hook to strip CVS template lines when committing
Add a hook function to strip all lines beginning with "CVS:" from the commit message as CVS does. Do this only if 'log-edit-vc-backend' is 'CVS'. (Bug#72341) * lisp/vc/log-edit.el (log-edit-done-strip-cvs-lines): New command. (log-edit-done-hook): Add it as an option. * test/lisp/vc/log-edit-tests.el (log-edit-done-strip-cvs-lines-helper): New function. (log-edit-done-strip-cvs-lines-cvs) (log-edit-done-strip-cvs-lines-non-cvs) (log-edit-done-strip-cvs-lines-only-cvs-colon-blank) (log-edit-done-strip-cvs-lines-only-cvs-colon): New test cases. * etc/NEWS: Mention log-edit-done-strip-cvs-lines.
This commit is contained in:
parent
4db604f375
commit
00e284fc52
3 changed files with 75 additions and 1 deletions
6
etc/NEWS
6
etc/NEWS
|
@ -1335,6 +1335,12 @@ the directory into which the repository was cloned.
|
|||
*** 'C-x v u' ('vc-revert') now works on directories listed in VC Directory.
|
||||
Reverting a directory means reverting changes to all files inside it.
|
||||
|
||||
*** New function 'log-edit-done-strip-cvs-lines'.
|
||||
This function strips all lines beginning with "CVS:" from the buffer.
|
||||
It is intended to be added to the 'log-edit-done-hook' so that
|
||||
'vc-cvs-checkin' behaves like invoking "cvs commit [files...]" from the
|
||||
command line.
|
||||
|
||||
** Package
|
||||
|
||||
+++
|
||||
|
|
|
@ -210,7 +210,8 @@ such as a bug-tracking system. The list of files about to be committed
|
|||
can be obtained from `log-edit-files'."
|
||||
:group 'log-edit
|
||||
:type '(hook :options (log-edit-set-common-indentation
|
||||
log-edit-add-to-changelog)))
|
||||
log-edit-add-to-changelog
|
||||
log-edit-done-strip-cvs-lines)))
|
||||
|
||||
(defcustom log-edit-strip-single-file-name nil
|
||||
"If non-nil, remove file name from single-file log entries."
|
||||
|
@ -927,6 +928,20 @@ This simply uses the local CVS/Template file."
|
|||
(goto-char (point-max))
|
||||
(insert-file-contents "CVS/Template"))))
|
||||
|
||||
(defun log-edit-done-strip-cvs-lines (&optional interactive)
|
||||
"Strip lines starting with \"CVS:\" from commit log message.
|
||||
When not called interactively do this only when the VC backend is CVS.
|
||||
This mimicks what CVS does when invoked as \\='cvs commit [files...]'."
|
||||
(interactive "p")
|
||||
(when (or interactive (eq log-edit-vc-backend 'CVS))
|
||||
(let ((case-fold-search nil))
|
||||
(goto-char (point-min))
|
||||
;; NB: While CVS defines CVSEDITPREFIX as "CVS: " it actually
|
||||
;; checks only the first four characters of af a line, i.e. "CVS:"
|
||||
;; to deal with editors that strip trailing whitespace.
|
||||
;; c.f. src/cvs.h and src/logmsg.c:do_editor()
|
||||
(flush-lines "^CVS:"))))
|
||||
|
||||
(defun log-edit-insert-cvs-rcstemplate ()
|
||||
"Insert the RCS commit log template from the CVS repository.
|
||||
This contacts the repository to get the rcstemplate file and
|
||||
|
|
|
@ -360,4 +360,57 @@ Report color and/or grayscale properly.
|
|||
(let ((fill-column 64)) (log-edit-fill-entry))
|
||||
(should (equal (buffer-string) wanted)))))
|
||||
|
||||
(defun log-edit-done-strip-cvs-lines-helper (initial-text wanted vc-backend)
|
||||
"Helper function for the log-edit-done-strip-cvs-lines tests.
|
||||
Tests that running log-edit-done-strip-cvs-lines as a log-edit-done-hook
|
||||
produces the WANTED string when run on INITIAL-TEXT with
|
||||
'log-edit-vc-backend' set to VC-BACKEND.\""
|
||||
(with-temp-buffer
|
||||
(let ((log-edit-done-hook 'log-edit-done-strip-cvs-lines)
|
||||
(log-edit-vc-backend vc-backend))
|
||||
(setq-local log-edit-callback #'(lambda () (interactive) nil))
|
||||
(insert initial-text)
|
||||
(log-edit-done)
|
||||
(should (equal (buffer-string) wanted)))))
|
||||
|
||||
(ert-deftest log-edit-done-strip-cvs-lines-cvs ()
|
||||
"Strip lines beginning with \"CVS:\" when using CVS as VC backend."
|
||||
(let (string wanted)
|
||||
(setq string "summary line
|
||||
first line
|
||||
CVS: Please evaluate your changes and consider the following.
|
||||
CVS: Abort checkin if you answer no.
|
||||
"
|
||||
wanted "summary line
|
||||
first line
|
||||
")
|
||||
(log-edit-done-strip-cvs-lines-helper string wanted 'CVS)))
|
||||
|
||||
(ert-deftest log-edit-done-strip-cvs-lines-non-cvs ()
|
||||
"Do not strip lines beginning with \"CVS:\" when not using CVS as VC backend."
|
||||
(let (string)
|
||||
(setq string "summary line
|
||||
first line
|
||||
CVS: Please evaluate your changes and consider the following.
|
||||
CVS: Abort checkin if you answer no.
|
||||
")
|
||||
(log-edit-done-strip-cvs-lines-helper string string nil)))
|
||||
|
||||
(ert-deftest log-edit-done-strip-cvs-lines-only-cvs-colon-blank ()
|
||||
"Strip lines that contain solely \"CVS: \" when using CVS as VC backend."
|
||||
(let (string wanted)
|
||||
(setq string "CVS: \n"
|
||||
wanted "")
|
||||
(log-edit-done-strip-cvs-lines-helper string wanted 'CVS)))
|
||||
|
||||
(ert-deftest log-edit-done-strip-cvs-lines-only-cvs-colon ()
|
||||
"Strip lines that contain solely \"CVS:\" when using CVS as VC backend."
|
||||
;; This test verifies that lines consisting only of "CVS:" (no blank
|
||||
;; after the colon) are stripped from the commit message.
|
||||
;; CVS does this to accomodate editors that delete trailing whitespace.
|
||||
(let (string wanted)
|
||||
(setq string "CVS:\n"
|
||||
wanted "")
|
||||
(log-edit-done-strip-cvs-lines-helper string wanted 'CVS)))
|
||||
|
||||
;;; log-edit-tests.el ends here
|
||||
|
|
Loading…
Add table
Reference in a new issue