Copy changes from tarballs when installing VC packages

* etc/NEWS: Document change.
* lisp/emacs-lisp/package-vc.el (package-vc--clone): Implement
logic to find and copy files from a previous installation.
(package-vc-install): Indicate the effect of the prefix argument
in the prompt.
This commit is contained in:
Philip Kaludercic 2026-05-16 16:31:13 +02:00
parent 407b5ce7ab
commit b13450973a
No known key found for this signature in database
2 changed files with 33 additions and 2 deletions

View file

@ -36,6 +36,16 @@ applies, and please also update docstrings as needed.
* Changes in Specialized Modes and Packages in Emacs 32.1
** Package
---
*** Package-vc can copy local changes from existing installations
When installing the latest release of a package, package-vc will propose
copying files from an existing, tarball installation of the same package
with the same version. This is useful if you have started making local
changes to your tarball installation, and then decide to check out the
repository to prepare a patch for the package maintainer.
* New Modes and Packages in Emacs 32.1

View file

@ -725,7 +725,25 @@ attribute in PKG-SPEC."
;; Check out the latest release if requested
(when (eq rev :last-release)
(if-let* ((release-rev (package-vc--release-rev pkg-desc)))
(vc-retrieve-tag dir release-rev)
(progn
(vc-retrieve-tag dir release-rev)
(when-let* ((vers (version-to-list
(lm-package-version (package-vc--main-file pkg-desc))))
(prev-desc (package-get-descriptor
name 'installed
(lambda (desc)
(version-list-= (package-desc-version desc)
vers))))
(_ (yes-or-no-p "Copy files from previous installation?")))
(let* ((remove (seq-remove
#'file-exists-p
(let ((default-directory dir))
(mapcar #'expand-file-name '("REAME-elpa"))))))
(copy-directory
(file-name-as-directory (package-desc-dir prev-desc))
(file-name-as-directory dir)
nil 'parents 'copy-contents)
(mapc #'delete-file remove))))
(message "No release revision was found, continuing...")))))
(defvar package-vc-non-code-file-names
@ -941,7 +959,10 @@ installs takes precedence."
;; symbols for completion.
(package-vc--archives-initialize)
(let* ((name-or-url (package-vc--read-package-name
"Fetch and install package: " t))
(if current-prefix-arg
"Fetch and install latest release of package: "
"Fetch and install package: ")
t))
(name (file-name-base (directory-file-name name-or-url))))
(when (string-empty-p name)
(user-error "Empty package name"))