aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Whitton2025-06-11 11:28:24 +0100
committerSean Whitton2025-06-11 11:28:24 +0100
commitbf418cd836c40795ec4ee19de5c5742d3ca698ea (patch)
treedb3f2ecff9da15b2951c66a6950c8d9b13988996
parentde2daa74bd5304364931fd19ad81a94f5f7d8d09 (diff)
downloademacs-bf418cd836c40795ec4ee19de5c5742d3ca698ea.tar.gz
emacs-bf418cd836c40795ec4ee19de5c5742d3ca698ea.zip
vc-next-action: Leave files unregistered if user aborts the checkin
* lisp/vc/vc.el (vc-only-files-state-and-model): Don't call vc-register. (vc-checkin): New REGISTER parameter. Call vc-register when it's non-nil. (vc-next-action): Pass new REGISTER parameter to vc-checkin.
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/vc/vc.el64
2 files changed, 47 insertions, 21 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 23b76da8cb2..e762e5ae8e1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1777,10 +1777,10 @@ These correspond to the existing 'z p' to pop a stash and 'P' to pop the
1777stash at point (deleting the stash at point is also bound to 'C-k'). 1777stash at point (deleting the stash at point is also bound to 'C-k').
1778 1778
1779--- 1779---
1780*** VC Directory now offers to register files when checking in mixed filesets. 1780*** VC Directory can now register files when checking in mixed filesets.
1781Previously, if some files to be checked in were unregistered but others 1781Previously, if some files to be checked in were unregistered but others
1782were added, removed or edited, Emacs would refuse to proceed. 1782were added, removed or edited, Emacs would refuse to proceed.
1783Now Emacs prompts to first register the unregistered files, so that all 1783Now Emacs prompts to register the unregistered files, so that all
1784files in the fileset are in a compatible state for a checkin. 1784files in the fileset are in a compatible state for a checkin.
1785 1785
1786+++ 1786+++
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 356eb2d7370..291d5d02fc8 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1377,12 +1377,25 @@ BACKEND is the VC backend responsible for FILES."
1377 ((cl-subsetp states '(added missing removed edited)) 1377 ((cl-subsetp states '(added missing removed edited))
1378 (setq state 'edited)) 1378 (setq state 'edited))
1379 1379
1380 ;; Special, but common case: 1380 ;; Special, but common case: checking in both changes and new
1381 ;; checking in both changes and new files at once. 1381 ;; files at once. The actual registration is delayed until
1382 ((and (cl-subsetp states '(added missing removed edited unregistered)) 1382 ;; `vc-checkin' so that if the user changes their mind while
1383 (y-or-n-p "Some files are unregistered; register them first?")) 1383 ;; entering the log message, we leave things as we found them.
1384 (vc-register (list backend 1384 ;;
1385 (cdr (assq 'unregistered states-alist)))) 1385 ;; An alternative would be to delay it until the backend
1386 ;; `vc-*-checkin'. The advantages would be that those
1387 ;; functions could complete the whole operation in fewer total
1388 ;; shell commands, and if the checkin itself fails they could
1389 ;; ensure the file is left unregistered then too (e.g. for Git
1390 ;; we may be able to use 'git add -N', though that would still
1391 ;; require a subsequent 'git reset').
1392 ;; The disadvantage would be a more complex VC API because we
1393 ;; would have to distinguish between backends which can and
1394 ;; can't handle registration and checkin together.
1395 ((and (cl-subsetp states
1396 '(added missing removed edited unregistered))
1397 (y-or-n-p "\
1398Some files are unregistered; register them before checking in?"))
1386 (setq state 'edited)) 1399 (setq state 'edited))
1387 1400
1388 (t 1401 (t
@@ -1470,7 +1483,7 @@ from which to check out the file(s)."
1470 (let* ((vc-fileset (vc-deduce-fileset nil t 'state-model-only-files)) 1483 (let* ((vc-fileset (vc-deduce-fileset nil t 'state-model-only-files))
1471 (backend (car vc-fileset)) 1484 (backend (car vc-fileset))
1472 (files (nth 1 vc-fileset)) 1485 (files (nth 1 vc-fileset))
1473 ;; (fileset-only-files (nth 2 vc-fileset)) 1486 (fileset-only-files (nth 2 vc-fileset))
1474 ;; FIXME: We used to call `vc-recompute-state' here. 1487 ;; FIXME: We used to call `vc-recompute-state' here.
1475 (state (nth 3 vc-fileset)) 1488 (state (nth 3 vc-fileset))
1476 ;; The backend should check that the checkout-model is consistent 1489 ;; The backend should check that the checkout-model is consistent
@@ -1550,6 +1563,9 @@ from which to check out the file(s)."
1550 (with-current-buffer visited 1563 (with-current-buffer visited
1551 (read-only-mode -1))))))) 1564 (read-only-mode -1)))))))
1552 ;; Allow user to revert files with no changes 1565 ;; Allow user to revert files with no changes
1566 ;; FIXME: This will never do anything because STATE will never
1567 ;; be `up-to-date' in this branch of the cond.
1568 ;; How did the code end up like this? --spwhitton
1553 (save-excursion 1569 (save-excursion
1554 (let (to-revert) 1570 (let (to-revert)
1555 (dolist (file files) 1571 (dolist (file files)
@@ -1570,17 +1586,22 @@ from which to check out the file(s)."
1570 ;; Remaining files need to be committed 1586 ;; Remaining files need to be committed
1571 (if (not ready-for-commit) 1587 (if (not ready-for-commit)
1572 (message "No files remain to be committed") 1588 (message "No files remain to be committed")
1573 (if (not verbose) 1589 ;; In the case there actually are any unregistered files then
1574 (vc-checkin ready-for-commit backend) 1590 ;; `vc-deduce-backend', via `vc-only-files-state-and-model',
1575 (let* ((revision (read-string "New revision or backend: ")) 1591 ;; has already prompted the user to approve registering them.
1576 (revision-downcase (downcase revision))) 1592 (let ((register (cl-remove-if #'vc-backend fileset-only-files)))
1577 (if (member 1593 (if (not verbose)
1578 revision-downcase 1594 (vc-checkin ready-for-commit backend nil nil nil nil register)
1579 (mapcar (lambda (arg) (downcase (symbol-name arg))) 1595 (let* ((revision (read-string "New revision or backend: "))
1580 vc-handled-backends)) 1596 (revision-downcase (downcase revision)))
1581 (let ((vsym (intern revision-downcase))) 1597 (if (member
1582 (dolist (file files) (vc-transfer-file file vsym))) 1598 revision-downcase
1583 (vc-checkin ready-for-commit backend nil nil revision))))))) 1599 (mapcar (lambda (arg) (downcase (symbol-name arg)))
1600 vc-handled-backends))
1601 (let ((vsym (intern revision-downcase)))
1602 (dolist (file files) (vc-transfer-file file vsym)))
1603 (vc-checkin ready-for-commit backend
1604 nil nil revision nil register))))))))
1584 ;; locked by somebody else (locking VCSes only) 1605 ;; locked by somebody else (locking VCSes only)
1585 ((stringp state) 1606 ((stringp state)
1586 ;; In the old days, we computed the revision once and used it on 1607 ;; In the old days, we computed the revision once and used it on
@@ -1891,7 +1912,8 @@ Type \\[vc-next-action] to check in changes.")
1891 (substitute-command-keys 1912 (substitute-command-keys
1892 "Please explain why you stole the lock. Type \\`C-c C-c' when done")))) 1913 "Please explain why you stole the lock. Type \\`C-c C-c' when done"))))
1893 1914
1894(defun vc-checkin (files backend &optional comment initial-contents rev patch-string) 1915(defun vc-checkin
1916 (files backend &optional comment initial-contents rev patch-string register)
1895 "Check in FILES. 1917 "Check in FILES.
1896 1918
1897COMMENT is a comment string; if omitted, a buffer is popped up to accept 1919COMMENT is a comment string; if omitted, a buffer is popped up to accept
@@ -1901,6 +1923,9 @@ initial contents of the log entry buffer.
1901The optional argument REV may be a string specifying the new revision 1923The optional argument REV may be a string specifying the new revision
1902level (only supported for some older VCSes, like RCS and CVS). 1924level (only supported for some older VCSes, like RCS and CVS).
1903The optional argument PATCH-STRING is a string to check in as a patch. 1925The optional argument PATCH-STRING is a string to check in as a patch.
1926If the optional argument REGISTER is non-nil, it should be a list of
1927files to register before checking in; if any of these are already
1928registered the checkin will abort.
1904 1929
1905Runs the normal hooks `vc-before-checkin-hook' and `vc-checkin-hook'." 1930Runs the normal hooks `vc-before-checkin-hook' and `vc-checkin-hook'."
1906 (run-hooks 'vc-before-checkin-hook) 1931 (run-hooks 'vc-before-checkin-hook)
@@ -1917,6 +1942,7 @@ Runs the normal hooks `vc-before-checkin-hook' and `vc-checkin-hook'."
1917 ;; RCS 5.7 gripes about whitespace-only comments too. 1942 ;; RCS 5.7 gripes about whitespace-only comments too.
1918 (unless (and comment (string-match "[^\t\n ]" comment)) 1943 (unless (and comment (string-match "[^\t\n ]" comment))
1919 (setq comment "*** empty log message ***")) 1944 (setq comment "*** empty log message ***"))
1945 (when register (vc-register (list backend files)))
1920 (cl-labels ((do-it () 1946 (cl-labels ((do-it ()
1921 ;; We used to change buffers to get local value of 1947 ;; We used to change buffers to get local value of
1922 ;; `vc-checkin-switches', but the (singular) local 1948 ;; `vc-checkin-switches', but the (singular) local