aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Badura2025-01-26 22:48:11 +0100
committerSean Whitton2025-03-09 14:28:25 +0800
commit00e284fc52b44fc3cb435a5d17ce58af1b753a34 (patch)
tree510aa7a4504f2782efd5b3746eb5c67267abaa0b
parent4db604f3751ffb6a1fc3fd4277445a8f94cec13f (diff)
downloademacs-00e284fc52b44fc3cb435a5d17ce58af1b753a34.tar.gz
emacs-00e284fc52b44fc3cb435a5d17ce58af1b753a34.zip
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.
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/vc/log-edit.el17
-rw-r--r--test/lisp/vc/log-edit-tests.el53
3 files changed, 75 insertions, 1 deletions
diff --git a/etc/NEWS b/etc/NEWS
index db49c4cde67..6cfed2932d4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1335,6 +1335,12 @@ the directory into which the repository was cloned.
1335*** 'C-x v u' ('vc-revert') now works on directories listed in VC Directory. 1335*** 'C-x v u' ('vc-revert') now works on directories listed in VC Directory.
1336Reverting a directory means reverting changes to all files inside it. 1336Reverting a directory means reverting changes to all files inside it.
1337 1337
1338*** New function 'log-edit-done-strip-cvs-lines'.
1339This function strips all lines beginning with "CVS:" from the buffer.
1340It is intended to be added to the 'log-edit-done-hook' so that
1341'vc-cvs-checkin' behaves like invoking "cvs commit [files...]" from the
1342command line.
1343
1338** Package 1344** Package
1339 1345
1340+++ 1346+++
diff --git a/lisp/vc/log-edit.el b/lisp/vc/log-edit.el
index bb85de8bd10..3eb614f6030 100644
--- a/lisp/vc/log-edit.el
+++ b/lisp/vc/log-edit.el
@@ -210,7 +210,8 @@ such as a bug-tracking system. The list of files about to be committed
210can be obtained from `log-edit-files'." 210can be obtained from `log-edit-files'."
211 :group 'log-edit 211 :group 'log-edit
212 :type '(hook :options (log-edit-set-common-indentation 212 :type '(hook :options (log-edit-set-common-indentation
213 log-edit-add-to-changelog))) 213 log-edit-add-to-changelog
214 log-edit-done-strip-cvs-lines)))
214 215
215(defcustom log-edit-strip-single-file-name nil 216(defcustom log-edit-strip-single-file-name nil
216 "If non-nil, remove file name from single-file log entries." 217 "If non-nil, remove file name from single-file log entries."
@@ -927,6 +928,20 @@ This simply uses the local CVS/Template file."
927 (goto-char (point-max)) 928 (goto-char (point-max))
928 (insert-file-contents "CVS/Template")))) 929 (insert-file-contents "CVS/Template"))))
929 930
931(defun log-edit-done-strip-cvs-lines (&optional interactive)
932 "Strip lines starting with \"CVS:\" from commit log message.
933When not called interactively do this only when the VC backend is CVS.
934This mimicks what CVS does when invoked as \\='cvs commit [files...]'."
935 (interactive "p")
936 (when (or interactive (eq log-edit-vc-backend 'CVS))
937 (let ((case-fold-search nil))
938 (goto-char (point-min))
939 ;; NB: While CVS defines CVSEDITPREFIX as "CVS: " it actually
940 ;; checks only the first four characters of af a line, i.e. "CVS:"
941 ;; to deal with editors that strip trailing whitespace.
942 ;; c.f. src/cvs.h and src/logmsg.c:do_editor()
943 (flush-lines "^CVS:"))))
944
930(defun log-edit-insert-cvs-rcstemplate () 945(defun log-edit-insert-cvs-rcstemplate ()
931 "Insert the RCS commit log template from the CVS repository. 946 "Insert the RCS commit log template from the CVS repository.
932This contacts the repository to get the rcstemplate file and 947This contacts the repository to get the rcstemplate file and
diff --git a/test/lisp/vc/log-edit-tests.el b/test/lisp/vc/log-edit-tests.el
index 005c336a3b6..6a312c6dac7 100644
--- a/test/lisp/vc/log-edit-tests.el
+++ b/test/lisp/vc/log-edit-tests.el
@@ -360,4 +360,57 @@ Report color and/or grayscale properly.
360 (let ((fill-column 64)) (log-edit-fill-entry)) 360 (let ((fill-column 64)) (log-edit-fill-entry))
361 (should (equal (buffer-string) wanted))))) 361 (should (equal (buffer-string) wanted)))))
362 362
363(defun log-edit-done-strip-cvs-lines-helper (initial-text wanted vc-backend)
364 "Helper function for the log-edit-done-strip-cvs-lines tests.
365Tests that running log-edit-done-strip-cvs-lines as a log-edit-done-hook
366produces the WANTED string when run on INITIAL-TEXT with
367'log-edit-vc-backend' set to VC-BACKEND.\""
368 (with-temp-buffer
369 (let ((log-edit-done-hook 'log-edit-done-strip-cvs-lines)
370 (log-edit-vc-backend vc-backend))
371 (setq-local log-edit-callback #'(lambda () (interactive) nil))
372 (insert initial-text)
373 (log-edit-done)
374 (should (equal (buffer-string) wanted)))))
375
376(ert-deftest log-edit-done-strip-cvs-lines-cvs ()
377 "Strip lines beginning with \"CVS:\" when using CVS as VC backend."
378 (let (string wanted)
379 (setq string "summary line
380first line
381CVS: Please evaluate your changes and consider the following.
382CVS: Abort checkin if you answer no.
383"
384 wanted "summary line
385first line
386")
387 (log-edit-done-strip-cvs-lines-helper string wanted 'CVS)))
388
389(ert-deftest log-edit-done-strip-cvs-lines-non-cvs ()
390 "Do not strip lines beginning with \"CVS:\" when not using CVS as VC backend."
391 (let (string)
392 (setq string "summary line
393first line
394CVS: Please evaluate your changes and consider the following.
395CVS: Abort checkin if you answer no.
396")
397 (log-edit-done-strip-cvs-lines-helper string string nil)))
398
399(ert-deftest log-edit-done-strip-cvs-lines-only-cvs-colon-blank ()
400 "Strip lines that contain solely \"CVS: \" when using CVS as VC backend."
401 (let (string wanted)
402 (setq string "CVS: \n"
403 wanted "")
404 (log-edit-done-strip-cvs-lines-helper string wanted 'CVS)))
405
406(ert-deftest log-edit-done-strip-cvs-lines-only-cvs-colon ()
407 "Strip lines that contain solely \"CVS:\" when using CVS as VC backend."
408 ;; This test verifies that lines consisting only of "CVS:" (no blank
409 ;; after the colon) are stripped from the commit message.
410 ;; CVS does this to accomodate editors that delete trailing whitespace.
411 (let (string wanted)
412 (setq string "CVS:\n"
413 wanted "")
414 (log-edit-done-strip-cvs-lines-helper string wanted 'CVS)))
415
363;;; log-edit-tests.el ends here 416;;; log-edit-tests.el ends here